@zthun/helpful-fn 9.11.9 → 9.11.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2146 +1,1919 @@
1
- import { v4 } from 'uuid';
2
- import { ja, enZA, enUS, enNZ, enIN, enIE, enGB, enCA, enAU } from 'date-fns/locale';
3
- import { TZDate } from '@date-fns/tz';
4
- import { startOfToday, parse, formatDate } from 'date-fns';
5
-
6
- /**
7
- * Represents a targeted point along a y axis.
8
- */ var ZVerticalAnchor = /*#__PURE__*/ function(ZVerticalAnchor) {
9
- /**
10
- * Top boundary.
11
- *
12
- * In vertical device space, this would equate to y = 0.
13
- */ ZVerticalAnchor["Top"] = "top";
14
- /**
15
- * Centerpoint between the top and bottom.
16
- */ ZVerticalAnchor["Middle"] = "middle";
17
- /**
18
- * Bottom boundary.
19
- *
20
- * In vertical device space, this would equate to y = Infinity.
21
- */ ZVerticalAnchor["Bottom"] = "bottom";
22
- return ZVerticalAnchor;
1
+ import { v4 } from "uuid";
2
+ import { enAU, enCA, enGB, enIE, enIN, enNZ, enUS, enZA, ja } from "date-fns/locale";
3
+ import { TZDate } from "@date-fns/tz";
4
+ import { formatDate, parse, startOfToday } from "date-fns";
5
+ //#region src/anchor/anchor.mts
6
+ /**
7
+ * Represents a targeted point along a y axis.
8
+ */ var ZVerticalAnchor = /* @__PURE__ */ function(ZVerticalAnchor) {
9
+ /**
10
+ * Top boundary.
11
+ *
12
+ * In vertical device space, this would equate to y = 0.
13
+ */ ZVerticalAnchor["Top"] = "top";
14
+ /**
15
+ * Centerpoint between the top and bottom.
16
+ */ ZVerticalAnchor["Middle"] = "middle";
17
+ /**
18
+ * Bottom boundary.
19
+ *
20
+ * In vertical device space, this would equate to y = Infinity.
21
+ */ ZVerticalAnchor["Bottom"] = "bottom";
22
+ return ZVerticalAnchor;
23
23
  }({});
24
24
  /**
25
- * Represents a targeted point along an x axis.
26
- */ var ZHorizontalAnchor = /*#__PURE__*/ function(ZHorizontalAnchor) {
27
- /**
28
- * Left boundary.
29
- *
30
- * In horizontal device space, this would equate to x = 0.
31
- */ ZHorizontalAnchor["Left"] = "left";
32
- /**
33
- * Centerpoint between the left and right boundary.
34
- */ ZHorizontalAnchor["Center"] = "center";
35
- /**
36
- * Right boundary.
37
- *
38
- * In horizontal device space, this would equate to x = Infinity.
39
- */ ZHorizontalAnchor["Right"] = "right";
40
- return ZHorizontalAnchor;
25
+ * Represents a targeted point along an x axis.
26
+ */ var ZHorizontalAnchor = /* @__PURE__ */ function(ZHorizontalAnchor) {
27
+ /**
28
+ * Left boundary.
29
+ *
30
+ * In horizontal device space, this would equate to x = 0.
31
+ */ ZHorizontalAnchor["Left"] = "left";
32
+ /**
33
+ * Centerpoint between the left and right boundary.
34
+ */ ZHorizontalAnchor["Center"] = "center";
35
+ /**
36
+ * Right boundary.
37
+ *
38
+ * In horizontal device space, this would equate to x = Infinity.
39
+ */ ZHorizontalAnchor["Right"] = "right";
40
+ return ZHorizontalAnchor;
41
41
  }({});
42
-
43
- function _define_property$7(obj, key, value) {
44
- if (key in obj) {
45
- Object.defineProperty(obj, key, {
46
- value: value,
47
- enumerable: true,
48
- configurable: true,
49
- writable: true
50
- });
51
- } else {
52
- obj[key] = value;
53
- }
54
- return obj;
55
- }
56
- /**
57
- * Represents an object that can be used to build a list of assertions.
58
- *
59
- * @example
60
- *
61
- * ```ts
62
- * import { ZAssert, createError } from '@zthun/helpful-fn';
63
- *
64
- * const user = readUser();
65
- *
66
- * ZAssert
67
- * .claim(user.name != null, 'User name is required')
68
- * .claim(user.email != null, 'User email is required')
69
- * .assert((m) => createError(m));
70
- * ```
71
- */ class ZAssert {
72
- /**
73
- * Initializes a new instance of a ZAssert with one claim.
74
- *
75
- * @param claim -
76
- * The claim to make.
77
- * @param msg -
78
- * The message to throw if the claim is false.
79
- *
80
- * @returns
81
- * A new ZAssert object with an initial claim.
82
- */ static claim(claim, msg) {
83
- return new ZAssert().claim(claim, msg);
84
- }
85
- /**
86
- * Adds a claim.
87
- *
88
- * @param claim -
89
- * The claim predicate.
90
- * @param msg -
91
- * The message to add if the claim fails.
92
- *
93
- * @returns This object.
94
- */ claim(claim, msg) {
95
- if (!claim) {
96
- this._messages.push(msg);
97
- }
98
- return this;
99
- }
100
- /**
101
- * Runs the assertion.
102
- *
103
- * @param fail -
104
- * The factory that is responsible for returning the specified error to throw.
105
- */ assert(fail) {
106
- if (this._messages.length === 1) {
107
- throw fail(this._messages[0]);
108
- }
109
- if (this._messages.length) {
110
- throw fail(this._messages);
111
- }
112
- }
113
- /**
114
- * Initializes a new instance of this object.
115
- */ constructor(){
116
- _define_property$7(this, "_messages", []);
117
- }
118
- }
119
-
120
- /**
121
- * Gets whether the candidate can represent an enumeration object of type TEnum.
122
- *
123
- * This is mostly helpful for type guarding value options in a type.
124
- *
125
- * @param enumeration -
126
- * The enumeration object that contains the values.
127
- * @param candidate -
128
- * The candidate to check.
129
- *
130
- * @returns
131
- * True if candidate can represents one of the white listed
132
- * object values in enumeration.
133
- */ function isEnum(enumeration, candidate) {
134
- return candidate != null && (typeof candidate === "string" || typeof candidate === "number") && Object.values(enumeration).includes(candidate);
42
+ //#endregion
43
+ //#region src/assert/assert.mts
44
+ /**
45
+ * Represents an object that can be used to build a list of assertions.
46
+ *
47
+ * @example
48
+ *
49
+ * ```ts
50
+ * import { ZAssert, createError } from '@zthun/helpful-fn';
51
+ *
52
+ * const user = readUser();
53
+ *
54
+ * ZAssert
55
+ * .claim(user.name != null, 'User name is required')
56
+ * .claim(user.email != null, 'User email is required')
57
+ * .assert((m) => createError(m));
58
+ * ```
59
+ */ var ZAssert = class ZAssert {
60
+ /**
61
+ * Initializes a new instance of a ZAssert with one claim.
62
+ *
63
+ * @param claim -
64
+ * The claim to make.
65
+ * @param msg -
66
+ * The message to throw if the claim is false.
67
+ *
68
+ * @returns
69
+ * A new ZAssert object with an initial claim.
70
+ */ static claim(claim, msg) {
71
+ return new ZAssert().claim(claim, msg);
72
+ }
73
+ _messages = [];
74
+ /**
75
+ * Initializes a new instance of this object.
76
+ */ constructor() {}
77
+ /**
78
+ * Adds a claim.
79
+ *
80
+ * @param claim -
81
+ * The claim predicate.
82
+ * @param msg -
83
+ * The message to add if the claim fails.
84
+ *
85
+ * @returns This object.
86
+ */ claim(claim, msg) {
87
+ if (!claim) this._messages.push(msg);
88
+ return this;
89
+ }
90
+ /**
91
+ * Runs the assertion.
92
+ *
93
+ * @param fail -
94
+ * The factory that is responsible for returning the specified error to throw.
95
+ */ assert(fail) {
96
+ if (this._messages.length === 1) throw fail(this._messages[0]);
97
+ if (this._messages.length) throw fail(this._messages);
98
+ }
99
+ };
100
+ //#endregion
101
+ //#region src/enum/is-enum.mts
102
+ /**
103
+ * Gets whether the candidate can represent an enumeration object of type TEnum.
104
+ *
105
+ * This is mostly helpful for type guarding value options in a type.
106
+ *
107
+ * @param enumeration -
108
+ * The enumeration object that contains the values.
109
+ * @param candidate -
110
+ * The candidate to check.
111
+ *
112
+ * @returns
113
+ * True if candidate can represents one of the white listed
114
+ * object values in enumeration.
115
+ */ function isEnum(enumeration, candidate) {
116
+ return candidate != null && (typeof candidate === "string" || typeof candidate === "number") && Object.values(enumeration).includes(candidate);
135
117
  }
136
-
137
- /**
138
- * Attempts to cast the candidate to an enumeration value.
139
- *
140
- * @param enumeration -
141
- * The enumeration type.
142
- * @param candidate -
143
- * The candidate to cast to the enum type.
144
- * @param fallback -
145
- * The fallback to use in the case that candidate
146
- * cannot represent the enumeration type.
147
- *
148
- * @returns
149
- * The candidate if candidate represents the enumeration type,
150
- * or fallback in the case that it does not.
151
- */ function castEnum(enumeration, candidate, fallback) {
152
- return isEnum(enumeration, candidate) ? candidate : fallback;
118
+ //#endregion
119
+ //#region src/cast/cast-enum.mts
120
+ /**
121
+ * Attempts to cast the candidate to an enumeration value.
122
+ *
123
+ * @param enumeration -
124
+ * The enumeration type.
125
+ * @param candidate -
126
+ * The candidate to cast to the enum type.
127
+ * @param fallback -
128
+ * The fallback to use in the case that candidate
129
+ * cannot represent the enumeration type.
130
+ *
131
+ * @returns
132
+ * The candidate if candidate represents the enumeration type,
133
+ * or fallback in the case that it does not.
134
+ */ function castEnum(enumeration, candidate, fallback) {
135
+ return isEnum(enumeration, candidate) ? candidate : fallback;
153
136
  }
154
-
155
- /**
156
- * Puts a . in front of name if one is not already there.
157
- *
158
- * If there are multiple dots in front of name, then
159
- * all dots but one is removed.
160
- *
161
- * @example
162
- *
163
- * ```ts
164
- * // Outputs .zip
165
- * castExtension('zip');
166
- *
167
- * // Outputs .zip
168
- * castExtension('.zip');
169
- *
170
- * // Outputs .zip
171
- * castExtension('...zip');
172
- * ```
173
- *
174
- * @param candidate -
175
- * The candidate extension
176
- *
177
- * @returns
178
- * The candidate prepended by a single dot.
179
- * If candidate is undefined, null, the empty
180
- * string, white space, or nothing but dots,
181
- * then the empty string is returned.
182
- */ function castExtension(candidate) {
183
- if (candidate == null) {
184
- return "";
185
- }
186
- const trimmed = candidate.trim();
187
- if (!trimmed) {
188
- return "";
189
- }
190
- const normalized = trimmed.replace(/^\.+/, "");
191
- if (!normalized) {
192
- return "";
193
- }
194
- return `.${normalized}`;
137
+ //#endregion
138
+ //#region src/cast/cast-extension.mts
139
+ /**
140
+ * Puts a . in front of name if one is not already there.
141
+ *
142
+ * If there are multiple dots in front of name, then
143
+ * all dots but one is removed.
144
+ *
145
+ * @example
146
+ *
147
+ * ```ts
148
+ * // Outputs .zip
149
+ * castExtension('zip');
150
+ *
151
+ * // Outputs .zip
152
+ * castExtension('.zip');
153
+ *
154
+ * // Outputs .zip
155
+ * castExtension('...zip');
156
+ * ```
157
+ *
158
+ * @param candidate -
159
+ * The candidate extension
160
+ *
161
+ * @returns
162
+ * The candidate prepended by a single dot.
163
+ * If candidate is undefined, null, the empty
164
+ * string, white space, or nothing but dots,
165
+ * then the empty string is returned.
166
+ */ function castExtension(candidate) {
167
+ if (candidate == null) return "";
168
+ const trimmed = candidate.trim();
169
+ if (!trimmed) return "";
170
+ const normalized = trimmed.replace(/^\.+/, "");
171
+ if (!normalized) return "";
172
+ return `.${normalized}`;
195
173
  }
196
-
197
- /**
198
- * Attempts to cast candidate to a number.
199
- *
200
- * This method assumes you want an actual number and
201
- * not NaN. In the case that candidate results in
202
- * NaN, then the fallback condition applies.
203
- *
204
- * @param candidate -
205
- * The candidate to cast.
206
- *
207
- * @returns
208
- * The casted number or undefined in the cast
209
- * that casting candidate would result in NaN.
210
- */ /**
211
- * Attempts to cast candidate to a number.
212
- *
213
- * This method assumes you want an actual number and
214
- * not NaN. In the case that candidate results in
215
- * NaN, then the fallback condition applies.
216
- *
217
- * @param candidate -
218
- * The candidate to cast.
219
- * @param fallback -
220
- * The fallback value in the case that the result
221
- * of casting candidate would result in NaN
222
- *
223
- * @returns
224
- * The casted number or fallback in the cast
225
- * that casting candidate would result in NaN.
226
- */ function castNumber(candidate, fallback) {
227
- try {
228
- const casted = Number(candidate);
229
- return Number.isNaN(casted) ? fallback : casted;
230
- } catch {
231
- return fallback;
232
- }
174
+ //#endregion
175
+ //#region src/cast/cast-number.mts
176
+ /**
177
+ * Attempts to cast candidate to a number.
178
+ *
179
+ * This method assumes you want an actual number and
180
+ * not NaN. In the case that candidate results in
181
+ * NaN, then the fallback condition applies.
182
+ *
183
+ * @param candidate -
184
+ * The candidate to cast.
185
+ *
186
+ * @returns
187
+ * The casted number or undefined in the cast
188
+ * that casting candidate would result in NaN.
189
+ */ /**
190
+ * Attempts to cast candidate to a number.
191
+ *
192
+ * This method assumes you want an actual number and
193
+ * not NaN. In the case that candidate results in
194
+ * NaN, then the fallback condition applies.
195
+ *
196
+ * @param candidate -
197
+ * The candidate to cast.
198
+ * @param fallback -
199
+ * The fallback value in the case that the result
200
+ * of casting candidate would result in NaN
201
+ *
202
+ * @returns
203
+ * The casted number or fallback in the cast
204
+ * that casting candidate would result in NaN.
205
+ */ function castNumber(candidate, fallback) {
206
+ try {
207
+ const casted = Number(candidate);
208
+ return Number.isNaN(casted) ? fallback : casted;
209
+ } catch {
210
+ return fallback;
211
+ }
233
212
  }
234
-
235
- /**
236
- * Calculates the total number of buckets you need to
237
- * store a number of items where each bucket can hold a
238
- * maximum weight of items.
239
- *
240
- * You can use this function to calculate groupings of
241
- * items based on total counts and sizes. A good example
242
- * usage would be to calculate the total number of pages
243
- * on a paginated list of items given a page size and item
244
- * count.
245
- *
246
- * @param weight -
247
- * The maximum weight a bucket can store. If this value receives
248
- * Infinity, then it will result in 1 or min buckets being returned,
249
- * whichever is larger. If this receives NaN, then this method will
250
- * result in NaN. Finally, if this receives a negative value, then
251
- * the result will be max.
252
- * @param items -
253
- * The total number of items you need to store where each item
254
- * counts as 1 towards the weight. If the total number of items
255
- * is Infinity, then this method will result in max buckets.
256
- * If this receives NaN, then this method will result in NaN. Finally,
257
- * if you pass 0, or a negative number of items, then result will be min.
258
- * @param min -
259
- * The bounded minimum value. If the total number of buckets
260
- * evaluates to less than this value, then this value is returned.
261
- * The default is 0.
262
- * @param max -
263
- * The bounded maximum value. If the total number of buckets
264
- * evaluates to more than this value, then this value is returned.
265
- * The default is Infinity.
266
- *
267
- * @returns
268
- * The number of buckets you need to store the total number
269
- * of items given that a single bucket can hold a max weight of items.
270
- * If either weight or items is NaN, then NaN will be returned regardless
271
- * of the opposite value. Passing a negative number is the same as
272
- * passing 0.
273
- *
274
- * @example
275
- *
276
- * ```ts
277
- * // The following will return 5 for numberOfPages since you need 5 buckets
278
- * // to store 101 number of items where each bucket can hold a max of 25
279
- * // items. The 5th page would be a page of 1 item, since 1 is the remainder.
280
- * const numberOfPages = countBuckets(25, 101);
281
- *
282
- * // In this case, the numberOfPages would be 1 here since our minimum buckets
283
- * // is 1. By default, this would be 0.
284
- * const numberOfPages = countBuckets(10, 0, 1);
285
- *
286
- * // In this case, we have more items that can be held in the number of buckets
287
- * // available, so only 4 is returned instead of the 5.
288
- * const numberOfPages = countBuckets(25, 101, undefined, 4);
289
- * ```
290
- */ function countBuckets(weight, items, min = 0, max = Infinity) {
291
- weight = Math.max(0, weight);
292
- items = Math.max(0, items);
293
- if (Number.isNaN(weight) || Number.isNaN(items)) {
294
- return NaN;
295
- }
296
- if (items === 0) {
297
- return min;
298
- }
299
- const boxes = weight === Infinity ? 1 : Math.ceil(items / weight);
300
- return Math.min(max, Math.max(min, boxes));
213
+ //#endregion
214
+ //#region src/count-buckets/count-buckets.mts
215
+ /**
216
+ * Calculates the total number of buckets you need to
217
+ * store a number of items where each bucket can hold a
218
+ * maximum weight of items.
219
+ *
220
+ * You can use this function to calculate groupings of
221
+ * items based on total counts and sizes. A good example
222
+ * usage would be to calculate the total number of pages
223
+ * on a paginated list of items given a page size and item
224
+ * count.
225
+ *
226
+ * @param weight -
227
+ * The maximum weight a bucket can store. If this value receives
228
+ * Infinity, then it will result in 1 or min buckets being returned,
229
+ * whichever is larger. If this receives NaN, then this method will
230
+ * result in NaN. Finally, if this receives a negative value, then
231
+ * the result will be max.
232
+ * @param items -
233
+ * The total number of items you need to store where each item
234
+ * counts as 1 towards the weight. If the total number of items
235
+ * is Infinity, then this method will result in max buckets.
236
+ * If this receives NaN, then this method will result in NaN. Finally,
237
+ * if you pass 0, or a negative number of items, then result will be min.
238
+ * @param min -
239
+ * The bounded minimum value. If the total number of buckets
240
+ * evaluates to less than this value, then this value is returned.
241
+ * The default is 0.
242
+ * @param max -
243
+ * The bounded maximum value. If the total number of buckets
244
+ * evaluates to more than this value, then this value is returned.
245
+ * The default is Infinity.
246
+ *
247
+ * @returns
248
+ * The number of buckets you need to store the total number
249
+ * of items given that a single bucket can hold a max weight of items.
250
+ * If either weight or items is NaN, then NaN will be returned regardless
251
+ * of the opposite value. Passing a negative number is the same as
252
+ * passing 0.
253
+ *
254
+ * @example
255
+ *
256
+ * ```ts
257
+ * // The following will return 5 for numberOfPages since you need 5 buckets
258
+ * // to store 101 number of items where each bucket can hold a max of 25
259
+ * // items. The 5th page would be a page of 1 item, since 1 is the remainder.
260
+ * const numberOfPages = countBuckets(25, 101);
261
+ *
262
+ * // In this case, the numberOfPages would be 1 here since our minimum buckets
263
+ * // is 1. By default, this would be 0.
264
+ * const numberOfPages = countBuckets(10, 0, 1);
265
+ *
266
+ * // In this case, we have more items that can be held in the number of buckets
267
+ * // available, so only 4 is returned instead of the 5.
268
+ * const numberOfPages = countBuckets(25, 101, undefined, 4);
269
+ * ```
270
+ */ function countBuckets(weight, items, min = 0, max = Infinity) {
271
+ weight = Math.max(0, weight);
272
+ items = Math.max(0, items);
273
+ if (Number.isNaN(weight) || Number.isNaN(items)) return NaN;
274
+ if (items === 0) return min;
275
+ const boxes = weight === Infinity ? 1 : Math.ceil(items / weight);
276
+ return Math.min(max, Math.max(min, boxes));
301
277
  }
302
-
303
- /**
304
- * A helper method to construct a JavaScript error object given a list of acceptable schema keys.
305
- *
306
- * @param problem -
307
- * A generic representation of the problem that occurred. This can be an Error object,
308
- * another object representing some kind of error, or some message representing the error.
309
- * If this is null or undefined, then a generic error is returned.
310
- * @param schema -
311
- * The list of acceptable object keys to look into problem. These will be recursively
312
- * evaluated to strip out the real error message. Note that this is in order of
313
- * priority. If schema[0] and schema[1] are both keys on problem, then schema[0] takes
314
- * a higher precedence than schema[1]. By default, the schema will look for properties
315
- * named, message, error, exception, and data, in that order.
316
- *
317
- * @returns
318
- * An error object that is the best evaluation of what the problem actually is.
319
- *
320
- * @example
321
- *
322
- * ```ts
323
- * // All of these result an Error with the message, 'Something went wrong'
324
- * const errorWithStringProblem = createError('Something went wrong');
325
- * const errorWithObjectProblemInSchema = createError({ error: 'Something went wrong'});
326
- * const errorWithCustomSchema = createError({ issue: 'Something went wrong'}, ['issue']);
327
- * const errorRecursive = createError({ error: { message: 'Something went wrong' }});
328
- *
329
- * // This would result in '[Object object]' as there is no way to figure out how to deconstruct this problem.
330
- * const errorCannotBeFound = createError({ wut: 'Something went wrong' });
331
- * ```
332
- */ function createError(problem, schema = [
333
- "message",
334
- "error",
335
- "exception",
336
- "data"
278
+ //#endregion
279
+ //#region src/create-error/create-error.mts
280
+ /**
281
+ * A helper method to construct a JavaScript error object given a list of acceptable schema keys.
282
+ *
283
+ * @param problem -
284
+ * A generic representation of the problem that occurred. This can be an Error object,
285
+ * another object representing some kind of error, or some message representing the error.
286
+ * If this is null or undefined, then a generic error is returned.
287
+ * @param schema -
288
+ * The list of acceptable object keys to look into problem. These will be recursively
289
+ * evaluated to strip out the real error message. Note that this is in order of
290
+ * priority. If schema[0] and schema[1] are both keys on problem, then schema[0] takes
291
+ * a higher precedence than schema[1]. By default, the schema will look for properties
292
+ * named, message, error, exception, and data, in that order.
293
+ *
294
+ * @returns
295
+ * An error object that is the best evaluation of what the problem actually is.
296
+ *
297
+ * @example
298
+ *
299
+ * ```ts
300
+ * // All of these result an Error with the message, 'Something went wrong'
301
+ * const errorWithStringProblem = createError('Something went wrong');
302
+ * const errorWithObjectProblemInSchema = createError({ error: 'Something went wrong'});
303
+ * const errorWithCustomSchema = createError({ issue: 'Something went wrong'}, ['issue']);
304
+ * const errorRecursive = createError({ error: { message: 'Something went wrong' }});
305
+ *
306
+ * // This would result in '[Object object]' as there is no way to figure out how to deconstruct this problem.
307
+ * const errorCannotBeFound = createError({ wut: 'Something went wrong' });
308
+ * ```
309
+ */ function createError(problem, schema = [
310
+ "message",
311
+ "error",
312
+ "exception",
313
+ "data"
337
314
  ]) {
338
- if (problem instanceof Error) {
339
- return problem;
340
- }
341
- if (problem == null) {
342
- return new Error();
343
- }
344
- for(let i = 0; i < schema.length; ++i){
345
- const key = schema[i];
346
- if (Object.prototype.hasOwnProperty.call(problem, key)) {
347
- return createError(problem[key]);
348
- }
349
- }
350
- return new Error(String(problem));
315
+ if (problem instanceof Error) return problem;
316
+ if (problem == null) return /* @__PURE__ */ new Error();
317
+ for (let i = 0; i < schema.length; ++i) {
318
+ const key = schema[i];
319
+ if (Object.prototype.hasOwnProperty.call(problem, key)) return createError(problem[key]);
320
+ }
321
+ return new Error(String(problem));
351
322
  }
352
-
353
- /**
354
- * Creates a globally unique identifier.
355
- *
356
- * The identifier holds to v4 of the UUID specification. A summary
357
- * of the specification can be found at
358
- * {@link https://commons.apache.org/sandbox/commons-id/uuid.html | Apache Commons UUID Documentation}.
359
- *
360
- * The official documentation of the UUID specification is under
361
- * {@link https://www.rfc-editor.org/info/rfc4122 | RFC 4122}
362
- *
363
- * @returns
364
- * A new generated globally unique identifier based on random bytes.
365
- *
366
- * @example
367
- *
368
- * ```ts
369
- * // Will get a value similar to 53e33fb6-d05a-4fa9-8dc0-b78e4feaa702
370
- * const guidA = createGuid();
371
- * // Will most likely not ever be equal to guidA
372
- * const guidB = createGuid();
373
- * ```
374
- */ const createGuid = v4;
375
-
376
- /**
377
- * Supported locales from date-fns.
378
- *
379
- * This should not be exported. This is an internal helper.
380
- */ const LocaleLookup = {
381
- [enAU.code]: enAU,
382
- [enCA.code]: enCA,
383
- [enGB.code]: enGB,
384
- [enIE.code]: enIE,
385
- [enIN.code]: enIN,
386
- [enNZ.code]: enNZ,
387
- [enUS.code]: enUS,
388
- [enZA.code]: enZA,
389
- [ja.code]: ja
323
+ //#endregion
324
+ //#region src/create-guid/create-guid.mts
325
+ /**
326
+ * Creates a globally unique identifier.
327
+ *
328
+ * The identifier holds to v4 of the UUID specification. A summary
329
+ * of the specification can be found at
330
+ * {@link https://commons.apache.org/sandbox/commons-id/uuid.html | Apache Commons UUID Documentation}.
331
+ *
332
+ * The official documentation of the UUID specification is under
333
+ * {@link https://www.rfc-editor.org/info/rfc4122 | RFC 4122}
334
+ *
335
+ * @returns
336
+ * A new generated globally unique identifier based on random bytes.
337
+ *
338
+ * @example
339
+ *
340
+ * ```ts
341
+ * // Will get a value similar to 53e33fb6-d05a-4fa9-8dc0-b78e4feaa702
342
+ * const guidA = createGuid();
343
+ * // Will most likely not ever be equal to guidA
344
+ * const guidB = createGuid();
345
+ * ```
346
+ */ var createGuid = v4;
347
+ //#endregion
348
+ //#region src/culture/locale-lookup.mts
349
+ /**
350
+ * Supported locales from date-fns.
351
+ *
352
+ * This should not be exported. This is an internal helper.
353
+ */ var LocaleLookup = {
354
+ [enAU.code]: enAU,
355
+ [enCA.code]: enCA,
356
+ [enGB.code]: enGB,
357
+ [enIE.code]: enIE,
358
+ [enIN.code]: enIN,
359
+ [enNZ.code]: enNZ,
360
+ [enUS.code]: enUS,
361
+ [enZA.code]: enZA,
362
+ [ja.code]: ja
390
363
  };
391
-
392
- /**
393
- * Returns the users current culture (locale).
394
- *
395
- * @returns
396
- * The current locale.
397
- */ function culture() {
398
- const locale = Intl.DateTimeFormat().resolvedOptions().locale;
399
- return locale;
364
+ //#endregion
365
+ //#region src/culture/culture.mts
366
+ /**
367
+ * Returns the users current culture (locale).
368
+ *
369
+ * @returns
370
+ * The current locale.
371
+ */ function culture() {
372
+ return Intl.DateTimeFormat().resolvedOptions().locale;
400
373
  }
401
374
  /**
402
- * Returns all supported cultures.
403
- *
404
- * @returns
405
- * A list of currently supported culture codes.
406
- */ function cultures() {
407
- return Object.keys(LocaleLookup);
375
+ * Returns all supported cultures.
376
+ *
377
+ * @returns
378
+ * A list of currently supported culture codes.
379
+ */ function cultures() {
380
+ return Object.keys(LocaleLookup);
408
381
  }
409
-
410
- /**
411
- * Returns the user's current timezone.
412
- *
413
- * @returns
414
- * The users current timezone.
415
- */ function userTimeZone() {
416
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
382
+ //#endregion
383
+ //#region src/date/timezone.mts
384
+ /**
385
+ * Returns the user's current timezone.
386
+ *
387
+ * @returns
388
+ * The users current timezone.
389
+ */ function userTimeZone() {
390
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
417
391
  }
418
392
  /**
419
- * Returns the list of all supported timezones.
420
- *
421
- * @returns
422
- * A list of all timezone values.
423
- */ function timeZones() {
424
- return Intl.supportedValuesOf("timeZone");
393
+ * Returns the list of all supported timezones.
394
+ *
395
+ * @returns
396
+ * A list of all timezone values.
397
+ */ function timeZones() {
398
+ return Intl.supportedValuesOf("timeZone");
425
399
  }
426
-
427
- /**
428
- * Parses a string value back to a date format.
429
- *
430
- *
431
- * @param value -
432
- * The value to parse
433
- * @param options -
434
- * The options to parse with. The most important option here is format.
435
- * If the format is not specified, then the standard zoned ISO 8601
436
- * format is used. The timezone is also used in the case the date
437
- * does not supply it for string values. If the timezone is not specified
438
- * then the users timezone is assumed. Finally, the cultural local will
439
- * default to the users current culture if not specified.
440
- *
441
- * @returns
442
- * The date object parsed from the value. Returns null
443
- * if the value parsed with the given options results in an
444
- * invalid date.
445
- */ function parseDateTime(value, options = {}) {
446
- const { fallback = null } = options;
447
- if (value == null) {
448
- return fallback;
449
- }
450
- if (typeof value === "number") {
451
- const candidate = new Date(value);
452
- return Number.isNaN(candidate.getTime()) ? fallback : candidate;
453
- }
454
- if (value instanceof Date) {
455
- return Number.isNaN(value.getTime()) ? fallback : value;
456
- }
457
- const { format = ZDateFormats.Iso, culture: culture$1 = culture(), timeZone = userTimeZone() } = options;
458
- const locale = LocaleLookup[culture$1];
459
- const reference = new TZDate(startOfToday()).withTimeZone(timeZone);
460
- const result = parse(value, format, reference, {
461
- locale
462
- });
463
- return Number.isNaN(result.getTime()) ? fallback : result;
400
+ //#endregion
401
+ //#region src/date/parse-date.mts
402
+ /**
403
+ * Parses a string value back to a date format.
404
+ *
405
+ *
406
+ * @param value -
407
+ * The value to parse
408
+ * @param options -
409
+ * The options to parse with. The most important option here is format.
410
+ * If the format is not specified, then the standard zoned ISO 8601
411
+ * format is used. The timezone is also used in the case the date
412
+ * does not supply it for string values. If the timezone is not specified
413
+ * then the users timezone is assumed. Finally, the cultural local will
414
+ * default to the users current culture if not specified.
415
+ *
416
+ * @returns
417
+ * The date object parsed from the value. Returns null
418
+ * if the value parsed with the given options results in an
419
+ * invalid date.
420
+ */ function parseDateTime(value, options = {}) {
421
+ const { fallback = null } = options;
422
+ if (value == null) return fallback;
423
+ if (typeof value === "number") {
424
+ const candidate = new Date(value);
425
+ return Number.isNaN(candidate.getTime()) ? fallback : candidate;
426
+ }
427
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? fallback : value;
428
+ const { format = ZDateFormats.Iso, culture: culture$2 = culture(), timeZone = userTimeZone() } = options;
429
+ const locale = LocaleLookup[culture$2];
430
+ const result = parse(value, format, new TZDate(startOfToday()).withTimeZone(timeZone), { locale });
431
+ return Number.isNaN(result.getTime()) ? fallback : result;
464
432
  }
465
-
466
- /**
467
- * Similar to {@link parseDateTime} but tries multiple supported formats.
468
- *
469
- * @param value -
470
- * The value to parse that may result in a date.
471
- * @param options -
472
- * The options for guessing the date. These will be forwarded to parse
473
- * for processing.
474
- */ function guessDateTime(value, options = {}) {
475
- const { fallback = null } = options;
476
- if (value == null) {
477
- return fallback;
478
- }
479
- const { supportedFormats = Object.values(ZDateFormats) } = options;
480
- for (const fmt of supportedFormats){
481
- const inner = {
482
- ...options
483
- };
484
- inner.format = fmt;
485
- const result = parseDateTime(value, inner);
486
- if (result != null) {
487
- return result;
488
- }
489
- }
490
- return fallback;
433
+ //#endregion
434
+ //#region src/date/guess-date.mts
435
+ /**
436
+ * Similar to {@link parseDateTime} but tries multiple supported formats.
437
+ *
438
+ * @param value -
439
+ * The value to parse that may result in a date.
440
+ * @param options -
441
+ * The options for guessing the date. These will be forwarded to parse
442
+ * for processing.
443
+ */ function guessDateTime(value, options = {}) {
444
+ const { fallback = null } = options;
445
+ if (value == null) return fallback;
446
+ const { supportedFormats = Object.values(ZDateFormats) } = options;
447
+ for (const fmt of supportedFormats) {
448
+ const inner = { ...options };
449
+ inner.format = fmt;
450
+ const result = parseDateTime(value, inner);
451
+ if (result != null) return result;
452
+ }
453
+ return fallback;
491
454
  }
492
-
493
- /**
494
- * Basic date formats that are common for storage and usage.
495
- */ var ZDateFormats = /*#__PURE__*/ function(ZDateFormats) {
496
- /**
497
- * Standard {@link https://en.wikipedia.org/wiki/ISO_8601 | ISO-8601} format with date only.
498
- *
499
- * Using this should imply midnight user timezone.
500
- */ ZDateFormats["IsoDateOnly"] = "yyyy-MM-dd";
501
- /**
502
- * Standard {@link https://en.wikipedia.org/wiki/ISO_8601 | ISO-8601} format with time only.
503
- */ ZDateFormats["IsoTimeOnly"] = "HH:mm:ss.SSS";
504
- /**
505
- * Standard {@link https://en.wikipedia.org/wiki/ISO_8601 | ISO-8601} format without timezone specifier.
506
- */ ZDateFormats["IsoNoTimeZone"] = "yyyy-MM-dd'T'HH:mm:ss.SSS";
507
- /**
508
- * Standard {@link https://en.wikipedia.org/wiki/ISO_8601 | ISO-8601} format.
509
- */ ZDateFormats["Iso"] = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
510
- /**
511
- * Users local date (locale specific).
512
- */ ZDateFormats["LocalDate"] = "P";
513
- /**
514
- * User local time (locale specific).
515
- */ ZDateFormats["LocalTime"] = "p";
516
- /**
517
- * Date and time formatted with user specific locale.
518
- */ ZDateFormats["LocalDateTime"] = "Pp";
519
- return ZDateFormats;
455
+ //#endregion
456
+ //#region src/date/format-date.mts
457
+ /**
458
+ * Basic date formats that are common for storage and usage.
459
+ */ var ZDateFormats = /* @__PURE__ */ function(ZDateFormats) {
460
+ /**
461
+ * Standard {@link https://en.wikipedia.org/wiki/ISO_8601 | ISO-8601} format with date only.
462
+ *
463
+ * Using this should imply midnight user timezone.
464
+ */ ZDateFormats["IsoDateOnly"] = "yyyy-MM-dd";
465
+ /**
466
+ * Standard {@link https://en.wikipedia.org/wiki/ISO_8601 | ISO-8601} format with time only.
467
+ */ ZDateFormats["IsoTimeOnly"] = "HH:mm:ss.SSS";
468
+ /**
469
+ * Standard {@link https://en.wikipedia.org/wiki/ISO_8601 | ISO-8601} format without timezone specifier.
470
+ */ ZDateFormats["IsoNoTimeZone"] = "yyyy-MM-dd'T'HH:mm:ss.SSS";
471
+ /**
472
+ * Standard {@link https://en.wikipedia.org/wiki/ISO_8601 | ISO-8601} format.
473
+ */ ZDateFormats["Iso"] = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
474
+ /**
475
+ * Users local date (locale specific).
476
+ */ ZDateFormats["LocalDate"] = "P";
477
+ /**
478
+ * User local time (locale specific).
479
+ */ ZDateFormats["LocalTime"] = "p";
480
+ /**
481
+ * Date and time formatted with user specific locale.
482
+ */ ZDateFormats["LocalDateTime"] = "Pp";
483
+ return ZDateFormats;
520
484
  }({});
521
485
  /**
522
- * Formats a given value.
523
- *
524
- * @param value -
525
- * The value to format.
526
- * @param options -
527
- * The given options for the format.
528
- *
529
- * @returns
530
- * If value is null or undefined, then the empty string is returned.
531
- * If value is a string, then the date is guessed from the string and
532
- * reformatted to the format specified by options. Otherwise,
533
- * the date or number specified by value is formatted to the culture,
534
- * timezone, and format specified in the options.
535
- */ function formatDateTime(value, options = {}) {
536
- const { format = "Pp", culture: culture$1 = culture(), timeZone = userTimeZone(), fallback = "" } = options;
537
- let date;
538
- if (value == null) {
539
- date = null;
540
- } else if (typeof value === "string") {
541
- date = guessDateTime(value, {
542
- ...options,
543
- fallback: null
544
- });
545
- } else {
546
- date = new Date(value);
547
- }
548
- if (date == null || Number.isNaN(date.getTime())) {
549
- return fallback;
550
- }
551
- const withTz = new TZDate(date, timeZone);
552
- return formatDate(withTz, format, {
553
- locale: LocaleLookup[culture$1]
554
- });
555
- }
556
-
557
- /**
558
- * Does replacement of interpolation, ${}, tokens in a string.
559
- *
560
- * @param tokenized -
561
- * The string that can contain interpolation tokens.
562
- * @param tokens -
563
- * The tokens to replace.
564
- *
565
- * @returns
566
- * A detokenized string that replaces the tokens with the values
567
- * in the token dictionary. If a value is missing in the token dictionary,
568
- * then the tokens are preserved. If the value of a token is null or
569
- * undefined explicitly, then any tokens in the tokenized string are
570
- * removed for that value.
571
- */ function detokenize(tokenized, tokens) {
572
- if (tokenized == null) return "";
573
- return tokenized.replace(/\$\{([^}]+)\}/g, (_, tokenName)=>{
574
- if (tokenName in tokens) {
575
- const value = tokens[tokenName];
576
- if (value === null || value === undefined) {
577
- return "";
578
- }
579
- return value;
580
- }
581
- return `\${${tokenName}}`; // leave token intact if not present in tokens
582
- });
583
- }
584
-
585
- /**
586
- * Returns true if an object is empty, null, or undefined.
587
- *
588
- * Note that this is different than lodash's isEmpty method.
589
- * Checking an empty array or empty string will result
590
- * in false.
591
- *
592
- * @param candidate -
593
- * The object to test.
594
- *
595
- * @returns
596
- * True if candidate is the empty object or
597
- * null. False otherwise.
598
- */ function isEmptyObject(candidate) {
599
- const candidateType = typeof candidate;
600
- return candidate == null || candidateType === "object" && Object.keys(candidate).length === 0;
486
+ * Formats a given value.
487
+ *
488
+ * @param value -
489
+ * The value to format.
490
+ * @param options -
491
+ * The given options for the format.
492
+ *
493
+ * @returns
494
+ * If value is null or undefined, then the empty string is returned.
495
+ * If value is a string, then the date is guessed from the string and
496
+ * reformatted to the format specified by options. Otherwise,
497
+ * the date or number specified by value is formatted to the culture,
498
+ * timezone, and format specified in the options.
499
+ */ function formatDateTime(value, options = {}) {
500
+ const { format = "Pp", culture: culture$1 = culture(), timeZone = userTimeZone(), fallback = "" } = options;
501
+ let date;
502
+ if (value == null) date = null;
503
+ else if (typeof value === "string") date = guessDateTime(value, {
504
+ ...options,
505
+ fallback: null
506
+ });
507
+ else date = new Date(value);
508
+ if (date == null || Number.isNaN(date.getTime())) return fallback;
509
+ return formatDate(new TZDate(date, timeZone), format, { locale: LocaleLookup[culture$1] });
601
510
  }
602
-
603
- /**
604
- * Information for an enum value.
605
- *
606
- * This is useful for front end development when
607
- * you want to map an enumeration like value to
608
- * things like a display name, description, and
609
- * avatar. ECMAScript does not support decorators
610
- * for literal fields so this is an alternative
611
- * to describe that kind of information.
612
- *
613
- * This is similar to Metadata from helpful-query,
614
- * but it's much more specific and specialized
615
- * to enumerations.
616
- */ function _define_property$6(obj, key, value) {
617
- if (key in obj) {
618
- Object.defineProperty(obj, key, {
619
- value: value,
620
- enumerable: true,
621
- configurable: true,
622
- writable: true
623
- });
624
- } else {
625
- obj[key] = value;
626
- }
627
- return obj;
511
+ //#endregion
512
+ //#region src/detokenize/detokenize.mts
513
+ /**
514
+ * Does replacement of interpolation, ${}, tokens in a string.
515
+ *
516
+ * @param tokenized -
517
+ * The string that can contain interpolation tokens.
518
+ * @param tokens -
519
+ * The tokens to replace.
520
+ *
521
+ * @returns
522
+ * A detokenized string that replaces the tokens with the values
523
+ * in the token dictionary. If a value is missing in the token dictionary,
524
+ * then the tokens are preserved. If the value of a token is null or
525
+ * undefined explicitly, then any tokens in the tokenized string are
526
+ * removed for that value.
527
+ */ function detokenize(tokenized, tokens) {
528
+ if (tokenized == null) return "";
529
+ return tokenized.replace(/\$\{([^}]+)\}/g, (_, tokenName) => {
530
+ if (tokenName in tokens) {
531
+ const value = tokens[tokenName];
532
+ if (value === null || value === void 0) return "";
533
+ return value;
534
+ }
535
+ return `\${${tokenName}}`;
536
+ });
628
537
  }
629
- /**
630
- * Builds information for an enum.
631
- */ class ZEnumInfoBuilder {
632
- /**
633
- * The display name of the enum.
634
- *
635
- * @param name -
636
- * The display name of the enum.
637
- *
638
- * @returns
639
- * This object.
640
- */ name(name) {
641
- this._metadata.name = name;
642
- return this;
643
- }
644
- /**
645
- * Text description of the enum.
646
- *
647
- * @param description -
648
- * Text description of what the value means.
649
- *
650
- * @returns
651
- * This object.
652
- */ description(description) {
653
- this._metadata.description = description;
654
- return this;
655
- }
656
- /**
657
- * The avatar representation of the enum.
658
- *
659
- * @param avatar -
660
- * The avatar representation of what the value
661
- * is. This can be anything but should be related
662
- * to the framework it is being developed for.
663
- *
664
- * @returns
665
- * This object.
666
- */ avatar(avatar) {
667
- this._metadata.avatar = avatar;
668
- return this;
669
- }
670
- /**
671
- * Returns a shallow copy of the metadata.
672
- *
673
- * @returns
674
- * A shallow copy of the metadata.
675
- */ build() {
676
- return {
677
- ...this._metadata
678
- };
679
- }
680
- /**
681
- * Initializes a new instance of this object.
682
- *
683
- * @param value -
684
- * The value to initialize with.
685
- */ constructor(value){
686
- _define_property$6(this, "_metadata", void 0);
687
- this._metadata = {
688
- value
689
- };
690
- }
538
+ //#endregion
539
+ //#region src/empty/is-empty-object.mts
540
+ /**
541
+ * Returns true if an object is empty, null, or undefined.
542
+ *
543
+ * Note that this is different than lodash's isEmpty method.
544
+ * Checking an empty array or empty string will result
545
+ * in false.
546
+ *
547
+ * @param candidate -
548
+ * The object to test.
549
+ *
550
+ * @returns
551
+ * True if candidate is the empty object or
552
+ * null. False otherwise.
553
+ */ function isEmptyObject(candidate) {
554
+ return candidate == null || typeof candidate === "object" && Object.keys(candidate).length === 0;
691
555
  }
692
-
693
- const BYTES_PER_KIBIBYTE = 1024;
694
- const BYTES_PER_MEBIBYTE = 1048576; // 1024 ^ 2
695
- const BYTES_PER_GIBIBYTE = 1073741824; // 1024 ^ 3
696
- const BYTES_PER_TEBIBYTE = 1099511627776; // 1024 ^ 4
697
- const BYTES_PER_PEBIBYTE = 1125899906842624; // 1024 ^ 5
556
+ //#endregion
557
+ //#region src/enum/enum-info.mts
558
+ /**
559
+ * Information for an enum value.
560
+ *
561
+ * This is useful for front end development when
562
+ * you want to map an enumeration like value to
563
+ * things like a display name, description, and
564
+ * avatar. ECMAScript does not support decorators
565
+ * for literal fields so this is an alternative
566
+ * to describe that kind of information.
567
+ *
568
+ * This is similar to Metadata from helpful-query,
569
+ * but it's much more specific and specialized
570
+ * to enumerations.
571
+ */ /**
572
+ * Builds information for an enum.
573
+ */ var ZEnumInfoBuilder = class {
574
+ _metadata;
575
+ /**
576
+ * Initializes a new instance of this object.
577
+ *
578
+ * @param value -
579
+ * The value to initialize with.
580
+ */ constructor(value) {
581
+ this._metadata = { value };
582
+ }
583
+ /**
584
+ * The display name of the enum.
585
+ *
586
+ * @param name -
587
+ * The display name of the enum.
588
+ *
589
+ * @returns
590
+ * This object.
591
+ */ name(name) {
592
+ this._metadata.name = name;
593
+ return this;
594
+ }
595
+ /**
596
+ * Text description of the enum.
597
+ *
598
+ * @param description -
599
+ * Text description of what the value means.
600
+ *
601
+ * @returns
602
+ * This object.
603
+ */ description(description) {
604
+ this._metadata.description = description;
605
+ return this;
606
+ }
607
+ /**
608
+ * The avatar representation of the enum.
609
+ *
610
+ * @param avatar -
611
+ * The avatar representation of what the value
612
+ * is. This can be anything but should be related
613
+ * to the framework it is being developed for.
614
+ *
615
+ * @returns
616
+ * This object.
617
+ */ avatar(avatar) {
618
+ this._metadata.avatar = avatar;
619
+ return this;
620
+ }
621
+ /**
622
+ * Returns a shallow copy of the metadata.
623
+ *
624
+ * @returns
625
+ * A shallow copy of the metadata.
626
+ */ build() {
627
+ return { ...this._metadata };
628
+ }
629
+ };
630
+ //#endregion
631
+ //#region src/file-size/file-size.mts
632
+ var BYTES_PER_KIBIBYTE = 1024;
633
+ var BYTES_PER_MEBIBYTE = 1048576;
634
+ var BYTES_PER_GIBIBYTE = 1073741824;
635
+ var BYTES_PER_TEBIBYTE = 1099511627776;
636
+ var BYTES_PER_PEBIBYTE = 0x4000000000000;
698
637
  function bytes(bytesPerUnit, amount) {
699
- return Math.ceil(bytesPerUnit * amount);
638
+ return Math.ceil(bytesPerUnit * amount);
700
639
  }
701
640
  /**
702
- * Returns the total number of bytes for the wanted amount of kibibytes.
703
- *
704
- * A kibibyte is 1024 bytes.
705
- *
706
- * @param amount -
707
- * The total number of kibibytes to convert to bytes.
708
- *
709
- * @returns
710
- * The total number of bytes in the given amount of kibibytes.
711
- */ const kibibytes = bytes.bind(null, BYTES_PER_KIBIBYTE);
712
- /**
713
- * @see {@link kibibytes}
714
- */ const kib = kibibytes;
715
- /**
716
- * Returns the total number of bytes for the wanted number of mebibytes.
717
- *
718
- * A mebibyte is 1024 kibibytes.
719
- *
720
- * @param amount -
721
- * The total amount of mebibytes to convert to bytes.
722
- *
723
- * @returns
724
- * The total number of bytes in the given amount of mebibytes.
725
- */ const mebibytes = bytes.bind(null, BYTES_PER_MEBIBYTE);
726
- /**
727
- * @see {@link mebibytes}
728
- */ const mib = mebibytes;
729
- /**
730
- * Returns the total number of bytes for the wanted number of gibibytes.
731
- *
732
- * A gibibyte is 1024 mebibytes.
733
- *
734
- * @param amount -
735
- * The total amount of gibibytes to convert to bytes.
736
- *
737
- * @returns
738
- * The total number of bytes in the given amount of gibibytes.
739
- */ const gibibytes = bytes.bind(null, BYTES_PER_GIBIBYTE);
740
- /**
741
- * @see {@link gibibytes}
742
- */ const gib = gibibytes;
743
- /**
744
- * Returns the total number of bytes for the wanted number of tebibytes.
745
- *
746
- * A tebibyte is 1024 gibibytes.
747
- *
748
- * @param amount -
749
- * The total amount of tebibytes to convert to bytes.
750
- *
751
- * @returns
752
- * The total number of bytes in the given amount of tebibytes.
753
- */ const tebibytes = bytes.bind(null, BYTES_PER_TEBIBYTE);
754
- /**
755
- * @see {@link tebibytes}
756
- */ const tib = tebibytes;
757
- /**
758
- * Returns the total number of bytes for the wanted number of pebibytes.
759
- *
760
- * A pebibytes is 1024 tebibytes.
761
- *
762
- * @param amount -
763
- * The total amount of pebibytes to convert to bytes.
764
- *
765
- * @returns
766
- * The total number of bytes in the given amount of pebibytes.
767
- */ const pebibytes = bytes.bind(null, BYTES_PER_PEBIBYTE);
768
- /**
769
- * @see {@link pebibytes}
770
- */ const pib = pebibytes;
771
-
772
- /**
773
- * Returns the first value in an argument list that matches a predicate.
774
- *
775
- * @param predicate -
776
- * The match method against each value argument.
777
- * @param fallback -
778
- * The fallback value in the case that all arguments fail
779
- * the predicate.
780
- * @param first -
781
- * The first value to check.
782
- * @param remaining -
783
- * The remaining values beyond the first to check.
784
- * @param T -
785
- * The type of data that will be enumerated.
786
- *
787
- * @returns
788
- * The first value for where predicate returns true for the given argument value.
789
- * If first and all values of remaining fail the predicate then fallback is returned.
790
- */ function firstWhere(predicate, fallback, first, ...remaining) {
791
- if (predicate(first)) {
792
- return first;
793
- }
794
- for(let i = 0; i < remaining.length; ++i){
795
- const val = remaining[i];
796
- if (predicate(val)) {
797
- return val;
798
- }
799
- }
800
- return fallback;
641
+ * Returns the total number of bytes for the wanted amount of kibibytes.
642
+ *
643
+ * A kibibyte is 1024 bytes.
644
+ *
645
+ * @param amount -
646
+ * The total number of kibibytes to convert to bytes.
647
+ *
648
+ * @returns
649
+ * The total number of bytes in the given amount of kibibytes.
650
+ */ var kibibytes = bytes.bind(null, BYTES_PER_KIBIBYTE);
651
+ /**
652
+ * @see {@link kibibytes}
653
+ */ var kib = kibibytes;
654
+ /**
655
+ * Returns the total number of bytes for the wanted number of mebibytes.
656
+ *
657
+ * A mebibyte is 1024 kibibytes.
658
+ *
659
+ * @param amount -
660
+ * The total amount of mebibytes to convert to bytes.
661
+ *
662
+ * @returns
663
+ * The total number of bytes in the given amount of mebibytes.
664
+ */ var mebibytes = bytes.bind(null, BYTES_PER_MEBIBYTE);
665
+ /**
666
+ * @see {@link mebibytes}
667
+ */ var mib = mebibytes;
668
+ /**
669
+ * Returns the total number of bytes for the wanted number of gibibytes.
670
+ *
671
+ * A gibibyte is 1024 mebibytes.
672
+ *
673
+ * @param amount -
674
+ * The total amount of gibibytes to convert to bytes.
675
+ *
676
+ * @returns
677
+ * The total number of bytes in the given amount of gibibytes.
678
+ */ var gibibytes = bytes.bind(null, BYTES_PER_GIBIBYTE);
679
+ /**
680
+ * @see {@link gibibytes}
681
+ */ var gib = gibibytes;
682
+ /**
683
+ * Returns the total number of bytes for the wanted number of tebibytes.
684
+ *
685
+ * A tebibyte is 1024 gibibytes.
686
+ *
687
+ * @param amount -
688
+ * The total amount of tebibytes to convert to bytes.
689
+ *
690
+ * @returns
691
+ * The total number of bytes in the given amount of tebibytes.
692
+ */ var tebibytes = bytes.bind(null, BYTES_PER_TEBIBYTE);
693
+ /**
694
+ * @see {@link tebibytes}
695
+ */ var tib = tebibytes;
696
+ /**
697
+ * Returns the total number of bytes for the wanted number of pebibytes.
698
+ *
699
+ * A pebibytes is 1024 tebibytes.
700
+ *
701
+ * @param amount -
702
+ * The total amount of pebibytes to convert to bytes.
703
+ *
704
+ * @returns
705
+ * The total number of bytes in the given amount of pebibytes.
706
+ */ var pebibytes = bytes.bind(null, BYTES_PER_PEBIBYTE);
707
+ /**
708
+ * @see {@link pebibytes}
709
+ */ var pib = pebibytes;
710
+ //#endregion
711
+ //#region src/first-where/first-where.mts
712
+ /**
713
+ * Returns the first value in an argument list that matches a predicate.
714
+ *
715
+ * @param predicate -
716
+ * The match method against each value argument.
717
+ * @param fallback -
718
+ * The fallback value in the case that all arguments fail
719
+ * the predicate.
720
+ * @param first -
721
+ * The first value to check.
722
+ * @param remaining -
723
+ * The remaining values beyond the first to check.
724
+ * @param T -
725
+ * The type of data that will be enumerated.
726
+ *
727
+ * @returns
728
+ * The first value for where predicate returns true for the given argument value.
729
+ * If first and all values of remaining fail the predicate then fallback is returned.
730
+ */ function firstWhere(predicate, fallback, first, ...remaining) {
731
+ if (predicate(first)) return first;
732
+ for (let i = 0; i < remaining.length; ++i) {
733
+ const val = remaining[i];
734
+ if (predicate(val)) return val;
735
+ }
736
+ return fallback;
801
737
  }
802
738
  /**
803
- * Returns the first value in args such that args is not null or undefined.
804
- *
805
- * @param fallback -
806
- * The fallback value in the case that all values in args are null/undefined.
807
- * @param first -
808
- * The first value to check.
809
- * @param remaining -
810
- * The remaining values beyond the first to check.
811
- * @param T -
812
- * The type of data that will be enumerated.
813
- *
814
- * @returns
815
- * The first value if it is not null or undefined. If first is undefined or null, then the first item
816
- * in remaining such that remaining[i] is not null or undefined is returned. If first and all values of
817
- * remaining are null or undefined, then fallback is returned.
818
- *
819
- * @example
820
- *
821
- * ```ts
822
- * // 'Defined'
823
- * const shouldBeDefined = firstDefined('Fallback', null, undefined, 'Defined');
824
- * // 'Fallback'
825
- * const shouldBeFallback = firstDefined('Fallback', null, undefined);
826
- * const shouldAlsoBeFallback = firstDefined('Fallback', undefined);
827
- * // 'First'
828
- * const shouldBeFirst = firstDefined('Fallback', 'First', null, 'Third');
829
- * ```
830
- */ function firstDefined(fallback, first, ...remaining) {
831
- return firstWhere((v)=>v != null, fallback, first, ...remaining);
739
+ * Returns the first value in args such that args is not null or undefined.
740
+ *
741
+ * @param fallback -
742
+ * The fallback value in the case that all values in args are null/undefined.
743
+ * @param first -
744
+ * The first value to check.
745
+ * @param remaining -
746
+ * The remaining values beyond the first to check.
747
+ * @param T -
748
+ * The type of data that will be enumerated.
749
+ *
750
+ * @returns
751
+ * The first value if it is not null or undefined. If first is undefined or null, then the first item
752
+ * in remaining such that remaining[i] is not null or undefined is returned. If first and all values of
753
+ * remaining are null or undefined, then fallback is returned.
754
+ *
755
+ * @example
756
+ *
757
+ * ```ts
758
+ * // 'Defined'
759
+ * const shouldBeDefined = firstDefined('Fallback', null, undefined, 'Defined');
760
+ * // 'Fallback'
761
+ * const shouldBeFallback = firstDefined('Fallback', null, undefined);
762
+ * const shouldAlsoBeFallback = firstDefined('Fallback', undefined);
763
+ * // 'First'
764
+ * const shouldBeFirst = firstDefined('Fallback', 'First', null, 'Third');
765
+ * ```
766
+ */ function firstDefined(fallback, first, ...remaining) {
767
+ return firstWhere((v) => v != null, fallback, first, ...remaining);
832
768
  }
833
769
  /**
834
- * Returns the first value in args such that args is truthy
835
- *
836
- * @param fallback -
837
- * The fallback value in the case that all values in args are falsy.
838
- * @param first -
839
- * The first value to check.
840
- * @param remaining -
841
- * The remaining values beyond the first to check.
842
- * @param T -
843
- * The type of data that will be enumerated.
844
- *
845
- * @returns
846
- * The first value if it is truthy. If first is falsy, then the first item
847
- * in remaining such that remaining[i] is truthy is returned. If first and
848
- * all values of remaining are falsy, then fallback is returned.
849
- *
850
- * @example
851
- *
852
- * ```ts
853
- * // 'Defined'
854
- * const shouldBeDefined = firstTruthy('Fallback', null, undefined, 'Defined');
855
- * // 'Fallback'
856
- * const shouldBeFallback = firstTruthy('Fallback', '', undefined);
857
- * const shouldAlsoBeFallback = firstDefined('Fallback', 0, false);
858
- * // 'First'
859
- * const shouldBeFirst = firstDefined('Fallback', 'First', null, false, 0, NaN);
860
- * ```
861
- */ function firstTruthy(fallback, first, ...remaining) {
862
- return firstWhere((v)=>!!v, fallback, first, ...remaining);
863
- }
864
-
865
- function _define_property$5(obj, key, value) {
866
- if (key in obj) {
867
- Object.defineProperty(obj, key, {
868
- value: value,
869
- enumerable: true,
870
- configurable: true,
871
- writable: true
872
- });
873
- } else {
874
- obj[key] = value;
875
- }
876
- return obj;
877
- }
878
- /**
879
- * An object that can be used to build an {@link IZQuadrilateralCorners} object.
880
- *
881
- * @param T -
882
- * The type of data to associate to each corner.
883
- */ class ZQuadrilateralCornersBuilder {
884
- /**
885
- * Sets the bottom left corner value.
886
- *
887
- * @param value -
888
- * The value to set.
889
- *
890
- * @returns
891
- * This object.
892
- */ bottomLeft(value) {
893
- this._corners.bottomLeft = value;
894
- return this;
895
- }
896
- /**
897
- * Sets the bottom right corner value.
898
- *
899
- * @param value -
900
- * The value to set.
901
- *
902
- * @returns
903
- * This object.
904
- */ bottomRight(value) {
905
- this._corners.bottomRight = value;
906
- return this;
907
- }
908
- /**
909
- * Sets the top left corner value.
910
- *
911
- * @param value -
912
- * The value to set.
913
- *
914
- * @returns
915
- * This object.
916
- */ topLeft(value) {
917
- this._corners.topLeft = value;
918
- return this;
919
- }
920
- /**
921
- * Sets the top right corner value.
922
- *
923
- * @param value -
924
- * The value to set.
925
- *
926
- * @returns
927
- * This object.
928
- */ topRight(value) {
929
- this._corners.topRight = value;
930
- return this;
931
- }
932
- /**
933
- * Sets the bottom left and bottom right values.
934
- *
935
- * @param value -
936
- * The value for bottom left and bottom right.
937
- *
938
- * @returns
939
- * This object.
940
- */ bottom(value) {
941
- return this.bottomLeft(value).bottomRight(value);
942
- }
943
- /**
944
- * Sets the bottom left and top left values.
945
- *
946
- * @param value -
947
- * The value for bottom left and top left.
948
- *
949
- * @returns
950
- * This object.
951
- */ left(value) {
952
- return this.topLeft(value).bottomLeft(value);
953
- }
954
- /**
955
- * Sets the bottom right and top right values.
956
- *
957
- * @param value -
958
- * The value for bottom right and top right.
959
- *
960
- * @returns
961
- * This object.
962
- */ right(value) {
963
- return this.bottomRight(value).topRight(value);
964
- }
965
- /**
966
- * Sets the top left and top right values.
967
- *
968
- * @param value -
969
- * The value for top left and top right.
970
- *
971
- * @returns
972
- * This object.
973
- */ top(value) {
974
- return this.topLeft(value).topRight(value);
975
- }
976
- /**
977
- * Sets the corner values based on an object that
978
- * describes a set of quadrilateral corners.
979
- *
980
- * @param other -
981
- * The object that describes the corners.
982
- *
983
- * @returns
984
- * This object.
985
- */ from(other) {
986
- function isVerticals(candidate) {
987
- return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "bottom") || Object.prototype.hasOwnProperty.call(candidate, "top"));
988
- }
989
- function isHorizontals(candidate) {
990
- return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "left") || Object.prototype.hasOwnProperty.call(candidate, "right"));
991
- }
992
- function isCorners(candidate) {
993
- return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "bottomLeft") || Object.prototype.hasOwnProperty.call(candidate, "bottomRight") || Object.prototype.hasOwnProperty.call(candidate, "topLeft") || Object.prototype.hasOwnProperty.call(candidate, "topRight"));
994
- }
995
- const { bottomLeft, bottomRight, topLeft, topRight } = this._corners;
996
- if (isCorners(other)) {
997
- this._corners.bottomLeft = firstDefined(bottomLeft, other.bottomLeft);
998
- this._corners.bottomRight = firstDefined(bottomRight, other.bottomRight);
999
- this._corners.topLeft = firstDefined(topLeft, other.topLeft);
1000
- this._corners.topRight = firstDefined(topRight, other.topRight);
1001
- return this;
1002
- }
1003
- if (isVerticals(other)) {
1004
- this._corners.bottomLeft = firstDefined(bottomLeft, other.bottom);
1005
- this._corners.bottomRight = firstDefined(bottomRight, other.bottom);
1006
- this._corners.topLeft = firstDefined(topLeft, other.top);
1007
- this._corners.topRight = firstDefined(topRight, other.top);
1008
- return this;
1009
- }
1010
- if (isHorizontals(other)) {
1011
- this._corners.bottomLeft = firstDefined(bottomLeft, other.left);
1012
- this._corners.bottomRight = firstDefined(bottomRight, other.right);
1013
- this._corners.topLeft = firstDefined(topLeft, other.left);
1014
- this._corners.topRight = firstDefined(topRight, other.right);
1015
- return this;
1016
- }
1017
- if (!isEmptyObject(other)) {
1018
- this._corners.bottomLeft = firstDefined(bottomLeft, other);
1019
- this._corners.bottomRight = firstDefined(bottomRight, other);
1020
- this._corners.topLeft = firstDefined(topLeft, other);
1021
- this._corners.topRight = firstDefined(topRight, other);
1022
- }
1023
- return this;
1024
- }
1025
- /**
1026
- * Copies another corners object into this builder.
1027
- *
1028
- * @param other -
1029
- * The corners object to copy.
1030
- *
1031
- * @returns
1032
- * This object.
1033
- */ copy(other) {
1034
- this._corners = structuredClone(other);
1035
- return this;
1036
- }
1037
- /**
1038
- * Builds the corners.
1039
- *
1040
- * @returns
1041
- * The built corners.
1042
- */ build() {
1043
- return structuredClone(this._corners);
1044
- }
1045
- constructor(start){
1046
- _define_property$5(this, "_corners", void 0);
1047
- this._corners = {
1048
- bottomLeft: start,
1049
- bottomRight: start,
1050
- topLeft: start,
1051
- topRight: start
1052
- };
1053
- }
1054
- }
1055
-
1056
- function _define_property$4(obj, key, value) {
1057
- if (key in obj) {
1058
- Object.defineProperty(obj, key, {
1059
- value: value,
1060
- enumerable: true,
1061
- configurable: true,
1062
- writable: true
1063
- });
1064
- } else {
1065
- obj[key] = value;
1066
- }
1067
- return obj;
770
+ * Returns the first value in args such that args is truthy
771
+ *
772
+ * @param fallback -
773
+ * The fallback value in the case that all values in args are falsy.
774
+ * @param first -
775
+ * The first value to check.
776
+ * @param remaining -
777
+ * The remaining values beyond the first to check.
778
+ * @param T -
779
+ * The type of data that will be enumerated.
780
+ *
781
+ * @returns
782
+ * The first value if it is truthy. If first is falsy, then the first item
783
+ * in remaining such that remaining[i] is truthy is returned. If first and
784
+ * all values of remaining are falsy, then fallback is returned.
785
+ *
786
+ * @example
787
+ *
788
+ * ```ts
789
+ * // 'Defined'
790
+ * const shouldBeDefined = firstTruthy('Fallback', null, undefined, 'Defined');
791
+ * // 'Fallback'
792
+ * const shouldBeFallback = firstTruthy('Fallback', '', undefined);
793
+ * const shouldAlsoBeFallback = firstDefined('Fallback', 0, false);
794
+ * // 'First'
795
+ * const shouldBeFirst = firstDefined('Fallback', 'First', null, false, 0, NaN);
796
+ * ```
797
+ */ function firstTruthy(fallback, first, ...remaining) {
798
+ return firstWhere((v) => !!v, fallback, first, ...remaining);
1068
799
  }
1069
- /**
1070
- * Represents a builder for a quadrilateral object.
1071
- */ class ZQuadrilateralBuilder {
1072
- /**
1073
- * Sets the bottom value.
1074
- *
1075
- * @param bottom -
1076
- * The bottom value.
1077
- *
1078
- * @returns
1079
- * This object.
1080
- */ bottom(bottom) {
1081
- this._quad.bottom = bottom;
1082
- return this;
1083
- }
1084
- /**
1085
- * Sets the left value.
1086
- *
1087
- * @param left -
1088
- * The left value.
1089
- *
1090
- * @returns
1091
- * This object.
1092
- */ left(left) {
1093
- this._quad.left = left;
1094
- return this;
1095
- }
1096
- /**
1097
- * Sets the right value.
1098
- *
1099
- * @param right -
1100
- * The right value.
1101
- *
1102
- * @returns
1103
- * This object.
1104
- */ right(right) {
1105
- this._quad.right = right;
1106
- return this;
1107
- }
1108
- /**
1109
- * Sets the top value.
1110
- *
1111
- * @param top -
1112
- * The top value.
1113
- *
1114
- * @returns
1115
- * This object.
1116
- */ top(top) {
1117
- this._quad.top = top;
1118
- return this;
1119
- }
1120
- /**
1121
- * Sets the left and right value.
1122
- *
1123
- * @param x -
1124
- * The left and right value.
1125
- *
1126
- * @returns
1127
- * This object.
1128
- */ x(x) {
1129
- return this.left(x).right(x);
1130
- }
1131
- /**
1132
- * Sets the top and bottom value.
1133
- *
1134
- * @param y -
1135
- * The top and bottom value.
1136
- *
1137
- * @returns
1138
- * This object.
1139
- */ y(y) {
1140
- return this.bottom(y).top(y);
1141
- }
1142
- /**
1143
- * Constructs a full quadrilateral from an object that describes a quadrilateral.
1144
- *
1145
- * Note the limitations of this method. If T is of type Quadrilateral or Point2d,
1146
- * then this method's behavior is undefined and it will most likely build a
1147
- * corrupt object.
1148
- *
1149
- * @param other -
1150
- * The object to build from.
1151
- *
1152
- * @returns
1153
- * This object.
1154
- */ from(other) {
1155
- function isPoint2d(candidate) {
1156
- return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "x") || Object.prototype.hasOwnProperty.call(candidate, "y"));
1157
- }
1158
- function isQuadrilateral(candidate) {
1159
- return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "bottom") || Object.prototype.hasOwnProperty.call(candidate, "left") || Object.prototype.hasOwnProperty.call(candidate, "right") || Object.prototype.hasOwnProperty.call(candidate, "top"));
1160
- }
1161
- if (isQuadrilateral(other)) {
1162
- this._quad.bottom = firstDefined(this._quad.bottom, other.bottom);
1163
- this._quad.left = firstDefined(this._quad.left, other.left);
1164
- this._quad.right = firstDefined(this._quad.right, other.right);
1165
- this._quad.top = firstDefined(this._quad.top, other.top);
1166
- return this;
1167
- }
1168
- if (isPoint2d(other)) {
1169
- this._quad.bottom = firstDefined(this._quad.bottom, other.y);
1170
- this._quad.left = firstDefined(this._quad.left, other.x);
1171
- this._quad.right = firstDefined(this._quad.right, other.x);
1172
- this._quad.top = firstDefined(this._quad.top, other.y);
1173
- return this;
1174
- }
1175
- if (!isEmptyObject(other)) {
1176
- this._quad.bottom = firstDefined(this._quad.bottom, other);
1177
- this._quad.left = firstDefined(this._quad.left, other);
1178
- this._quad.right = firstDefined(this._quad.right, other);
1179
- this._quad.top = firstDefined(this._quad.top, other);
1180
- }
1181
- return this;
1182
- }
1183
- /**
1184
- * Copies another quadrilateral object into the current instance.
1185
- *
1186
- * @param other -
1187
- * The quadrilateral object to copy.
1188
- *
1189
- * @returns
1190
- * This object.
1191
- */ copy(other) {
1192
- // The copy is done this way instead of a structured
1193
- // copy because we want to support things like
1194
- // copy(other.getBoundingClientRect()) which
1195
- // is immutable when working on the client.
1196
- this._quad.left = other.left;
1197
- this._quad.right = other.right;
1198
- this._quad.top = other.top;
1199
- this._quad.bottom = other.bottom;
1200
- return this;
1201
- }
1202
- /**
1203
- * Returns the built quadrilateral object.
1204
- *
1205
- * @returns
1206
- * The built quadrilateral.
1207
- */ build() {
1208
- return structuredClone(this._quad);
1209
- }
1210
- /**
1211
- * Initializes a new instance of this object.
1212
- *
1213
- * @param start -
1214
- * The starting value.
1215
- */ constructor(start){
1216
- _define_property$4(this, "_quad", void 0);
1217
- this._quad = {
1218
- bottom: start,
1219
- left: start,
1220
- right: start,
1221
- top: start
1222
- };
1223
- }
1224
- }
1225
-
1226
- function _define_property$3(obj, key, value) {
1227
- if (key in obj) {
1228
- Object.defineProperty(obj, key, {
1229
- value: value,
1230
- enumerable: true,
1231
- configurable: true,
1232
- writable: true
1233
- });
1234
- } else {
1235
- obj[key] = value;
1236
- }
1237
- return obj;
1238
- }
1239
- /**
1240
- * Represents a helper object that can run calculations on a numeric quadrilateral.
1241
- */ class ZRectangle {
1242
- /**
1243
- * Calculates the width of the rectangle.
1244
- *
1245
- * @returns
1246
- * The numeric width of the rectangle.
1247
- */ width() {
1248
- const { left, right } = this.sides;
1249
- return right - left;
1250
- }
1251
- /**
1252
- * Calculates the height of the rectangle.
1253
- *
1254
- * @returns
1255
- * The numeric height of the rectangle.
1256
- */ height() {
1257
- const { top, bottom } = this.sides;
1258
- return bottom - top;
1259
- }
1260
- /**
1261
- * Calculates the area of the rectangle.
1262
- *
1263
- * @returns
1264
- * The numeric area of the rectangle.
1265
- */ area() {
1266
- return this.width() * this.height();
1267
- }
1268
- /**
1269
- * Takes a candidate and attaches it to this rectangle that matches the anchor points.
1270
- *
1271
- * @param anchor -
1272
- * The anchor point of this rectangle.
1273
- * @param candidate -
1274
- * The candidate rectangle to move
1275
- * @param candidateAnchor -
1276
- * The anchor point of the candidate rectangle.
1277
- *
1278
- * @returns
1279
- * A new quadrilateral that has it's placement such that if candidate was moved
1280
- * to this resulting position, would have its candidateAnchor be in the same
1281
- * place as this rectangles specified anchor.
1282
- */ attach(anchor, candidate, candidateAnchor) {
1283
- const _candidate = new ZRectangle(candidate);
1284
- const { x: ax, y: ay } = this.point(anchor);
1285
- const { x: ox, y: oy } = new ZRectangle(candidate).point(candidateAnchor);
1286
- const left = candidate.left + (ax - ox);
1287
- const top = candidate.top + (ay - oy);
1288
- const bottom = top + _candidate.height();
1289
- const right = left + _candidate.width();
1290
- return new ZQuadrilateralBuilder(0).left(left).right(right).top(top).bottom(bottom).build();
1291
- }
1292
- /**
1293
- * Takes the candidate quadrilateral and adjusts it's coordinates to fit inside this rectangle.
1294
- *
1295
- * This is done by shifting the rectangle left, right, up, and down to make sure it is bounded
1296
- * inside.
1297
- *
1298
- * If the candidate width or height is larger than this rectangle, thus it cannot fit, then
1299
- * the candidate will be centered on the dimension where it is too big to fit.
1300
- *
1301
- * @param candidate -
1302
- * The candidate quadrilateral to fit.
1303
- *
1304
- * @returns
1305
- * A new quadrilateral that offsets candidate so that it can fit inside this
1306
- * rectangle.
1307
- */ offsetToFit(candidate) {
1308
- let _candidate = candidate;
1309
- const candidateRectangle = new ZRectangle(candidate);
1310
- if (candidateRectangle.width() > this.width()) {
1311
- // Center the horizontal
1312
- const { x: cx } = candidateRectangle.middleCenter();
1313
- const { x: tx } = this.middleCenter();
1314
- _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).left(_candidate.left - (cx - tx)).right(_candidate.right - (cx - tx)).build();
1315
- } else {
1316
- if (_candidate.left < this.sides.left) {
1317
- // Move the candidate to the right.
1318
- _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).left(this.sides.left).right(_candidate.right + (this.sides.left - _candidate.left)).build();
1319
- }
1320
- if (_candidate.right > this.sides.right) {
1321
- // Move the candidate to the left.
1322
- _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).right(this.sides.right).left(_candidate.left - (_candidate.right - this.sides.right)).build();
1323
- }
1324
- }
1325
- if (candidateRectangle.height() > this.height()) {
1326
- // Center the vertical
1327
- const { y: cy } = candidateRectangle.middleCenter();
1328
- const { y: ty } = this.middleCenter();
1329
- _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).top(_candidate.top - (cy - ty)).bottom(_candidate.bottom - (cy - ty)).build();
1330
- } else {
1331
- if (_candidate.bottom > this.sides.bottom) {
1332
- // Move the candidate up.
1333
- _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).bottom(this.sides.bottom).top(_candidate.top - (_candidate.bottom - this.sides.bottom)).build();
1334
- }
1335
- if (_candidate.top < this.sides.top) {
1336
- // Move the candidate down
1337
- _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).top(this.sides.top).bottom(_candidate.bottom + (this.sides.top - _candidate.top)).build();
1338
- }
1339
- }
1340
- return _candidate;
1341
- }
1342
- /**
1343
- * Calculates the (x, y) point given an anchor target.
1344
- *
1345
- * @param anchor -
1346
- * The anchor target to calculate the point for.
1347
- *
1348
- * @returns
1349
- * The numeric width of the rectangle.
1350
- */ point(anchor) {
1351
- const { bottom, left, right, top } = this.sides;
1352
- const [vertical, horizontal] = anchor;
1353
- const v = {
1354
- [ZVerticalAnchor.Top]: top,
1355
- [ZVerticalAnchor.Middle]: (bottom + top) / 2,
1356
- [ZVerticalAnchor.Bottom]: bottom
1357
- };
1358
- const h = {
1359
- [ZHorizontalAnchor.Left]: left,
1360
- [ZHorizontalAnchor.Center]: (right + left) / 2,
1361
- [ZHorizontalAnchor.Right]: right
1362
- };
1363
- return {
1364
- x: h[horizontal],
1365
- y: v[vertical]
1366
- };
1367
- }
1368
- /**
1369
- * Initializes a new instance of this object.
1370
- *
1371
- * @param sides -
1372
- * The numeric sides of a quadrilateral.
1373
- */ constructor(sides){
1374
- _define_property$3(this, "sides", void 0);
1375
- /**
1376
- * Calculates the top left point of the rectangle.
1377
- *
1378
- * @returns
1379
- * The top left point of the rectangle.
1380
- */ _define_property$3(this, "topLeft", void 0);
1381
- /**
1382
- * Calculates the top center point of the rectangle.
1383
- *
1384
- * @returns
1385
- * The top center point of the rectangle.
1386
- */ _define_property$3(this, "topCenter", void 0);
1387
- /**
1388
- * Calculates the top right point of the rectangle.
1389
- *
1390
- * @returns
1391
- * The top right point of the rectangle.
1392
- */ _define_property$3(this, "topRight", void 0);
1393
- /**
1394
- * Calculates the middle left point of the rectangle.
1395
- *
1396
- * @returns
1397
- * The middle left point of the rectangle.
1398
- */ _define_property$3(this, "middleLeft", void 0);
1399
- /**
1400
- * Calculates the middle center point of the rectangle.
1401
- *
1402
- * @returns
1403
- * The middle center point of the rectangle.
1404
- */ _define_property$3(this, "middleCenter", void 0);
1405
- /**
1406
- * Calculates the middle right point of the rectangle.
1407
- *
1408
- * @returns
1409
- * The middle right point of the rectangle.
1410
- */ _define_property$3(this, "middleRight", void 0);
1411
- /**
1412
- * Calculates the bottom left point of the rectangle.
1413
- *
1414
- * @returns
1415
- * The bottom left point of the rectangle.
1416
- */ _define_property$3(this, "bottomLeft", void 0);
1417
- /**
1418
- * Calculates the bottom center point of the rectangle.
1419
- *
1420
- * @returns
1421
- * The bottom center point of the rectangle.
1422
- */ _define_property$3(this, "bottomCenter", void 0);
1423
- /**
1424
- * Calculates the bottom right point of the rectangle.
1425
- *
1426
- * @returns
1427
- * The bottom right point of the rectangle.
1428
- */ _define_property$3(this, "bottomRight", void 0);
1429
- this.sides = sides;
1430
- this.topLeft = this.point.bind(this, [
1431
- ZVerticalAnchor.Top,
1432
- ZHorizontalAnchor.Left
1433
- ]);
1434
- this.topCenter = this.point.bind(this, [
1435
- ZVerticalAnchor.Top,
1436
- ZHorizontalAnchor.Center
1437
- ]);
1438
- this.topRight = this.point.bind(this, [
1439
- ZVerticalAnchor.Top,
1440
- ZHorizontalAnchor.Right
1441
- ]);
1442
- this.middleLeft = this.point.bind(this, [
1443
- ZVerticalAnchor.Middle,
1444
- ZHorizontalAnchor.Left
1445
- ]);
1446
- this.middleCenter = this.point.bind(this, [
1447
- ZVerticalAnchor.Middle,
1448
- ZHorizontalAnchor.Center
1449
- ]);
1450
- this.middleRight = this.point.bind(this, [
1451
- ZVerticalAnchor.Middle,
1452
- ZHorizontalAnchor.Right
1453
- ]);
1454
- this.bottomLeft = this.point.bind(this, [
1455
- ZVerticalAnchor.Bottom,
1456
- ZHorizontalAnchor.Left
1457
- ]);
1458
- this.bottomCenter = this.point.bind(this, [
1459
- ZVerticalAnchor.Bottom,
1460
- ZHorizontalAnchor.Center
1461
- ]);
1462
- this.bottomRight = this.point.bind(this, [
1463
- ZVerticalAnchor.Bottom,
1464
- ZHorizontalAnchor.Right
1465
- ]);
1466
- }
1467
- }
1468
-
800
+ //#endregion
801
+ //#region src/geometry/quadrilateral.mts
802
+ /**
803
+ * Represents a builder for a quadrilateral object.
804
+ */ var ZQuadrilateralBuilder = class {
805
+ _quad;
806
+ /**
807
+ * Initializes a new instance of this object.
808
+ *
809
+ * @param start -
810
+ * The starting value.
811
+ */ constructor(start) {
812
+ this._quad = {
813
+ bottom: start,
814
+ left: start,
815
+ right: start,
816
+ top: start
817
+ };
818
+ }
819
+ /**
820
+ * Sets the bottom value.
821
+ *
822
+ * @param bottom -
823
+ * The bottom value.
824
+ *
825
+ * @returns
826
+ * This object.
827
+ */ bottom(bottom) {
828
+ this._quad.bottom = bottom;
829
+ return this;
830
+ }
831
+ /**
832
+ * Sets the left value.
833
+ *
834
+ * @param left -
835
+ * The left value.
836
+ *
837
+ * @returns
838
+ * This object.
839
+ */ left(left) {
840
+ this._quad.left = left;
841
+ return this;
842
+ }
843
+ /**
844
+ * Sets the right value.
845
+ *
846
+ * @param right -
847
+ * The right value.
848
+ *
849
+ * @returns
850
+ * This object.
851
+ */ right(right) {
852
+ this._quad.right = right;
853
+ return this;
854
+ }
855
+ /**
856
+ * Sets the top value.
857
+ *
858
+ * @param top -
859
+ * The top value.
860
+ *
861
+ * @returns
862
+ * This object.
863
+ */ top(top) {
864
+ this._quad.top = top;
865
+ return this;
866
+ }
867
+ /**
868
+ * Sets the left and right value.
869
+ *
870
+ * @param x -
871
+ * The left and right value.
872
+ *
873
+ * @returns
874
+ * This object.
875
+ */ x(x) {
876
+ return this.left(x).right(x);
877
+ }
878
+ /**
879
+ * Sets the top and bottom value.
880
+ *
881
+ * @param y -
882
+ * The top and bottom value.
883
+ *
884
+ * @returns
885
+ * This object.
886
+ */ y(y) {
887
+ return this.bottom(y).top(y);
888
+ }
889
+ /**
890
+ * Constructs a full quadrilateral from an object that describes a quadrilateral.
891
+ *
892
+ * Note the limitations of this method. If T is of type Quadrilateral or Point2d,
893
+ * then this method's behavior is undefined and it will most likely build a
894
+ * corrupt object.
895
+ *
896
+ * @param other -
897
+ * The object to build from.
898
+ *
899
+ * @returns
900
+ * This object.
901
+ */ from(other) {
902
+ function isPoint2d(candidate) {
903
+ return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "x") || Object.prototype.hasOwnProperty.call(candidate, "y"));
904
+ }
905
+ function isQuadrilateral(candidate) {
906
+ return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "bottom") || Object.prototype.hasOwnProperty.call(candidate, "left") || Object.prototype.hasOwnProperty.call(candidate, "right") || Object.prototype.hasOwnProperty.call(candidate, "top"));
907
+ }
908
+ if (isQuadrilateral(other)) {
909
+ this._quad.bottom = firstDefined(this._quad.bottom, other.bottom);
910
+ this._quad.left = firstDefined(this._quad.left, other.left);
911
+ this._quad.right = firstDefined(this._quad.right, other.right);
912
+ this._quad.top = firstDefined(this._quad.top, other.top);
913
+ return this;
914
+ }
915
+ if (isPoint2d(other)) {
916
+ this._quad.bottom = firstDefined(this._quad.bottom, other.y);
917
+ this._quad.left = firstDefined(this._quad.left, other.x);
918
+ this._quad.right = firstDefined(this._quad.right, other.x);
919
+ this._quad.top = firstDefined(this._quad.top, other.y);
920
+ return this;
921
+ }
922
+ if (!isEmptyObject(other)) {
923
+ this._quad.bottom = firstDefined(this._quad.bottom, other);
924
+ this._quad.left = firstDefined(this._quad.left, other);
925
+ this._quad.right = firstDefined(this._quad.right, other);
926
+ this._quad.top = firstDefined(this._quad.top, other);
927
+ }
928
+ return this;
929
+ }
930
+ /**
931
+ * Copies another quadrilateral object into the current instance.
932
+ *
933
+ * @param other -
934
+ * The quadrilateral object to copy.
935
+ *
936
+ * @returns
937
+ * This object.
938
+ */ copy(other) {
939
+ this._quad.left = other.left;
940
+ this._quad.right = other.right;
941
+ this._quad.top = other.top;
942
+ this._quad.bottom = other.bottom;
943
+ return this;
944
+ }
945
+ /**
946
+ * Returns the built quadrilateral object.
947
+ *
948
+ * @returns
949
+ * The built quadrilateral.
950
+ */ build() {
951
+ return structuredClone(this._quad);
952
+ }
953
+ };
954
+ //#endregion
955
+ //#region src/geometry/quadrilateral-corners.mts
956
+ /**
957
+ * An object that can be used to build an {@link IZQuadrilateralCorners} object.
958
+ *
959
+ * @param T -
960
+ * The type of data to associate to each corner.
961
+ */ var ZQuadrilateralCornersBuilder = class {
962
+ _corners;
963
+ constructor(start) {
964
+ this._corners = {
965
+ bottomLeft: start,
966
+ bottomRight: start,
967
+ topLeft: start,
968
+ topRight: start
969
+ };
970
+ }
971
+ /**
972
+ * Sets the bottom left corner value.
973
+ *
974
+ * @param value -
975
+ * The value to set.
976
+ *
977
+ * @returns
978
+ * This object.
979
+ */ bottomLeft(value) {
980
+ this._corners.bottomLeft = value;
981
+ return this;
982
+ }
983
+ /**
984
+ * Sets the bottom right corner value.
985
+ *
986
+ * @param value -
987
+ * The value to set.
988
+ *
989
+ * @returns
990
+ * This object.
991
+ */ bottomRight(value) {
992
+ this._corners.bottomRight = value;
993
+ return this;
994
+ }
995
+ /**
996
+ * Sets the top left corner value.
997
+ *
998
+ * @param value -
999
+ * The value to set.
1000
+ *
1001
+ * @returns
1002
+ * This object.
1003
+ */ topLeft(value) {
1004
+ this._corners.topLeft = value;
1005
+ return this;
1006
+ }
1007
+ /**
1008
+ * Sets the top right corner value.
1009
+ *
1010
+ * @param value -
1011
+ * The value to set.
1012
+ *
1013
+ * @returns
1014
+ * This object.
1015
+ */ topRight(value) {
1016
+ this._corners.topRight = value;
1017
+ return this;
1018
+ }
1019
+ /**
1020
+ * Sets the bottom left and bottom right values.
1021
+ *
1022
+ * @param value -
1023
+ * The value for bottom left and bottom right.
1024
+ *
1025
+ * @returns
1026
+ * This object.
1027
+ */ bottom(value) {
1028
+ return this.bottomLeft(value).bottomRight(value);
1029
+ }
1030
+ /**
1031
+ * Sets the bottom left and top left values.
1032
+ *
1033
+ * @param value -
1034
+ * The value for bottom left and top left.
1035
+ *
1036
+ * @returns
1037
+ * This object.
1038
+ */ left(value) {
1039
+ return this.topLeft(value).bottomLeft(value);
1040
+ }
1041
+ /**
1042
+ * Sets the bottom right and top right values.
1043
+ *
1044
+ * @param value -
1045
+ * The value for bottom right and top right.
1046
+ *
1047
+ * @returns
1048
+ * This object.
1049
+ */ right(value) {
1050
+ return this.bottomRight(value).topRight(value);
1051
+ }
1052
+ /**
1053
+ * Sets the top left and top right values.
1054
+ *
1055
+ * @param value -
1056
+ * The value for top left and top right.
1057
+ *
1058
+ * @returns
1059
+ * This object.
1060
+ */ top(value) {
1061
+ return this.topLeft(value).topRight(value);
1062
+ }
1063
+ /**
1064
+ * Sets the corner values based on an object that
1065
+ * describes a set of quadrilateral corners.
1066
+ *
1067
+ * @param other -
1068
+ * The object that describes the corners.
1069
+ *
1070
+ * @returns
1071
+ * This object.
1072
+ */ from(other) {
1073
+ function isVerticals(candidate) {
1074
+ return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "bottom") || Object.prototype.hasOwnProperty.call(candidate, "top"));
1075
+ }
1076
+ function isHorizontals(candidate) {
1077
+ return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "left") || Object.prototype.hasOwnProperty.call(candidate, "right"));
1078
+ }
1079
+ function isCorners(candidate) {
1080
+ return candidate != null && (Object.prototype.hasOwnProperty.call(candidate, "bottomLeft") || Object.prototype.hasOwnProperty.call(candidate, "bottomRight") || Object.prototype.hasOwnProperty.call(candidate, "topLeft") || Object.prototype.hasOwnProperty.call(candidate, "topRight"));
1081
+ }
1082
+ const { bottomLeft, bottomRight, topLeft, topRight } = this._corners;
1083
+ if (isCorners(other)) {
1084
+ this._corners.bottomLeft = firstDefined(bottomLeft, other.bottomLeft);
1085
+ this._corners.bottomRight = firstDefined(bottomRight, other.bottomRight);
1086
+ this._corners.topLeft = firstDefined(topLeft, other.topLeft);
1087
+ this._corners.topRight = firstDefined(topRight, other.topRight);
1088
+ return this;
1089
+ }
1090
+ if (isVerticals(other)) {
1091
+ this._corners.bottomLeft = firstDefined(bottomLeft, other.bottom);
1092
+ this._corners.bottomRight = firstDefined(bottomRight, other.bottom);
1093
+ this._corners.topLeft = firstDefined(topLeft, other.top);
1094
+ this._corners.topRight = firstDefined(topRight, other.top);
1095
+ return this;
1096
+ }
1097
+ if (isHorizontals(other)) {
1098
+ this._corners.bottomLeft = firstDefined(bottomLeft, other.left);
1099
+ this._corners.bottomRight = firstDefined(bottomRight, other.right);
1100
+ this._corners.topLeft = firstDefined(topLeft, other.left);
1101
+ this._corners.topRight = firstDefined(topRight, other.right);
1102
+ return this;
1103
+ }
1104
+ if (!isEmptyObject(other)) {
1105
+ this._corners.bottomLeft = firstDefined(bottomLeft, other);
1106
+ this._corners.bottomRight = firstDefined(bottomRight, other);
1107
+ this._corners.topLeft = firstDefined(topLeft, other);
1108
+ this._corners.topRight = firstDefined(topRight, other);
1109
+ }
1110
+ return this;
1111
+ }
1112
+ /**
1113
+ * Copies another corners object into this builder.
1114
+ *
1115
+ * @param other -
1116
+ * The corners object to copy.
1117
+ *
1118
+ * @returns
1119
+ * This object.
1120
+ */ copy(other) {
1121
+ this._corners = structuredClone(other);
1122
+ return this;
1123
+ }
1124
+ /**
1125
+ * Builds the corners.
1126
+ *
1127
+ * @returns
1128
+ * The built corners.
1129
+ */ build() {
1130
+ return structuredClone(this._corners);
1131
+ }
1132
+ };
1133
+ //#endregion
1134
+ //#region src/geometry/rectangle.mts
1135
+ /**
1136
+ * Represents a helper object that can run calculations on a numeric quadrilateral.
1137
+ */ var ZRectangle = class ZRectangle {
1138
+ sides;
1139
+ /**
1140
+ * Initializes a new instance of this object.
1141
+ *
1142
+ * @param sides -
1143
+ * The numeric sides of a quadrilateral.
1144
+ */ constructor(sides) {
1145
+ this.sides = sides;
1146
+ }
1147
+ /**
1148
+ * Calculates the width of the rectangle.
1149
+ *
1150
+ * @returns
1151
+ * The numeric width of the rectangle.
1152
+ */ width() {
1153
+ const { left, right } = this.sides;
1154
+ return right - left;
1155
+ }
1156
+ /**
1157
+ * Calculates the height of the rectangle.
1158
+ *
1159
+ * @returns
1160
+ * The numeric height of the rectangle.
1161
+ */ height() {
1162
+ const { top, bottom } = this.sides;
1163
+ return bottom - top;
1164
+ }
1165
+ /**
1166
+ * Calculates the area of the rectangle.
1167
+ *
1168
+ * @returns
1169
+ * The numeric area of the rectangle.
1170
+ */ area() {
1171
+ return this.width() * this.height();
1172
+ }
1173
+ /**
1174
+ * Takes a candidate and attaches it to this rectangle that matches the anchor points.
1175
+ *
1176
+ * @param anchor -
1177
+ * The anchor point of this rectangle.
1178
+ * @param candidate -
1179
+ * The candidate rectangle to move
1180
+ * @param candidateAnchor -
1181
+ * The anchor point of the candidate rectangle.
1182
+ *
1183
+ * @returns
1184
+ * A new quadrilateral that has it's placement such that if candidate was moved
1185
+ * to this resulting position, would have its candidateAnchor be in the same
1186
+ * place as this rectangles specified anchor.
1187
+ */ attach(anchor, candidate, candidateAnchor) {
1188
+ const _candidate = new ZRectangle(candidate);
1189
+ const { x: ax, y: ay } = this.point(anchor);
1190
+ const { x: ox, y: oy } = new ZRectangle(candidate).point(candidateAnchor);
1191
+ const left = candidate.left + (ax - ox);
1192
+ const top = candidate.top + (ay - oy);
1193
+ const bottom = top + _candidate.height();
1194
+ const right = left + _candidate.width();
1195
+ return new ZQuadrilateralBuilder(0).left(left).right(right).top(top).bottom(bottom).build();
1196
+ }
1197
+ /**
1198
+ * Takes the candidate quadrilateral and adjusts it's coordinates to fit inside this rectangle.
1199
+ *
1200
+ * This is done by shifting the rectangle left, right, up, and down to make sure it is bounded
1201
+ * inside.
1202
+ *
1203
+ * If the candidate width or height is larger than this rectangle, thus it cannot fit, then
1204
+ * the candidate will be centered on the dimension where it is too big to fit.
1205
+ *
1206
+ * @param candidate -
1207
+ * The candidate quadrilateral to fit.
1208
+ *
1209
+ * @returns
1210
+ * A new quadrilateral that offsets candidate so that it can fit inside this
1211
+ * rectangle.
1212
+ */ offsetToFit(candidate) {
1213
+ let _candidate = candidate;
1214
+ const candidateRectangle = new ZRectangle(candidate);
1215
+ if (candidateRectangle.width() > this.width()) {
1216
+ const { x: cx } = candidateRectangle.middleCenter();
1217
+ const { x: tx } = this.middleCenter();
1218
+ _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).left(_candidate.left - (cx - tx)).right(_candidate.right - (cx - tx)).build();
1219
+ } else {
1220
+ if (_candidate.left < this.sides.left) _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).left(this.sides.left).right(_candidate.right + (this.sides.left - _candidate.left)).build();
1221
+ if (_candidate.right > this.sides.right) _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).right(this.sides.right).left(_candidate.left - (_candidate.right - this.sides.right)).build();
1222
+ }
1223
+ if (candidateRectangle.height() > this.height()) {
1224
+ const { y: cy } = candidateRectangle.middleCenter();
1225
+ const { y: ty } = this.middleCenter();
1226
+ _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).top(_candidate.top - (cy - ty)).bottom(_candidate.bottom - (cy - ty)).build();
1227
+ } else {
1228
+ if (_candidate.bottom > this.sides.bottom) _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).bottom(this.sides.bottom).top(_candidate.top - (_candidate.bottom - this.sides.bottom)).build();
1229
+ if (_candidate.top < this.sides.top) _candidate = new ZQuadrilateralBuilder(0).copy(_candidate).top(this.sides.top).bottom(_candidate.bottom + (this.sides.top - _candidate.top)).build();
1230
+ }
1231
+ return _candidate;
1232
+ }
1233
+ /**
1234
+ * Calculates the (x, y) point given an anchor target.
1235
+ *
1236
+ * @param anchor -
1237
+ * The anchor target to calculate the point for.
1238
+ *
1239
+ * @returns
1240
+ * The numeric width of the rectangle.
1241
+ */ point(anchor) {
1242
+ const { bottom, left, right, top } = this.sides;
1243
+ const [vertical, horizontal] = anchor;
1244
+ const v = {
1245
+ [ZVerticalAnchor.Top]: top,
1246
+ [ZVerticalAnchor.Middle]: (bottom + top) / 2,
1247
+ [ZVerticalAnchor.Bottom]: bottom
1248
+ };
1249
+ return {
1250
+ x: {
1251
+ [ZHorizontalAnchor.Left]: left,
1252
+ [ZHorizontalAnchor.Center]: (right + left) / 2,
1253
+ [ZHorizontalAnchor.Right]: right
1254
+ }[horizontal],
1255
+ y: v[vertical]
1256
+ };
1257
+ }
1258
+ /**
1259
+ * Calculates the top left point of the rectangle.
1260
+ *
1261
+ * @returns
1262
+ * The top left point of the rectangle.
1263
+ */ topLeft = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Left]);
1264
+ /**
1265
+ * Calculates the top center point of the rectangle.
1266
+ *
1267
+ * @returns
1268
+ * The top center point of the rectangle.
1269
+ */ topCenter = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Center]);
1270
+ /**
1271
+ * Calculates the top right point of the rectangle.
1272
+ *
1273
+ * @returns
1274
+ * The top right point of the rectangle.
1275
+ */ topRight = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Right]);
1276
+ /**
1277
+ * Calculates the middle left point of the rectangle.
1278
+ *
1279
+ * @returns
1280
+ * The middle left point of the rectangle.
1281
+ */ middleLeft = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Left]);
1282
+ /**
1283
+ * Calculates the middle center point of the rectangle.
1284
+ *
1285
+ * @returns
1286
+ * The middle center point of the rectangle.
1287
+ */ middleCenter = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Center]);
1288
+ /**
1289
+ * Calculates the middle right point of the rectangle.
1290
+ *
1291
+ * @returns
1292
+ * The middle right point of the rectangle.
1293
+ */ middleRight = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Right]);
1294
+ /**
1295
+ * Calculates the bottom left point of the rectangle.
1296
+ *
1297
+ * @returns
1298
+ * The bottom left point of the rectangle.
1299
+ */ bottomLeft = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Left]);
1300
+ /**
1301
+ * Calculates the bottom center point of the rectangle.
1302
+ *
1303
+ * @returns
1304
+ * The bottom center point of the rectangle.
1305
+ */ bottomCenter = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Center]);
1306
+ /**
1307
+ * Calculates the bottom right point of the rectangle.
1308
+ *
1309
+ * @returns
1310
+ * The bottom right point of the rectangle.
1311
+ */ bottomRight = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right]);
1312
+ };
1313
+ //#endregion
1314
+ //#region src/global/global.mts
1469
1315
  /* v8 ignore start -- @preserve */ /* istanbul ignore file -- @preserve */ /**
1470
- * Resolves the global object without referencing DOM globals so this can be
1471
- * consumed in Node builds that do not include the `dom` lib.
1472
- */ const $global = globalThis; /* v8 ignore end -- @preserve */
1473
-
1474
- /**
1475
- * A set of parameters that can be used for a string join.
1476
- *
1477
- * Join lists can be a regular object, null, undefined, or a tuple where the
1478
- * first item is the object to join, and the second item is a boolean that specifies
1479
- * whether to include it if the value is truthy.
1480
- *
1481
- * @param T -
1482
- * The type of data to join.
1483
- */ /**
1484
- * Similar to Array.join but filters out null and undefined items.
1485
- *
1486
- * @param delimiter -
1487
- * The delimiter that separates the items.
1488
- * @param items -
1489
- * The items to join.
1490
- * @param T -
1491
- * The type of data to join.
1492
- *
1493
- * @returns
1494
- * A string that joins the items that are defined, separated by delimiter.
1495
- *
1496
- * @example
1497
- *
1498
- * ```ts
1499
- * // 'a b d'
1500
- * const joinBySpace = joinDefined(' ', 'a', 'b', ['c', false], null, undefined, ['d', true]);
1501
- * // (Empty String)
1502
- * const joinEmpty = joinDefined('?');
1503
- * ```
1504
- */ function joinDefined(delimiter, ...items) {
1505
- return items.map((item)=>item instanceof Array ? item[1] ? item[0] : null : item).filter((item)=>item != null).join(delimiter);
1506
- }
1507
- /**
1508
- * Alias to joinList with a space delimiter.
1509
- *
1510
- * @param items -
1511
- * The items to join.
1512
- *
1513
- * @returns
1514
- * A string that joins the items that are defined, separated by space delimiter.
1515
- *
1516
- * @see
1517
- * {@link joinDefined} for more information and examples.
1518
- */ const spaceJoinDefined = joinDefined.bind(null, " ");
1519
- /**
1520
- * Alias of spaceJoinList.
1521
- *
1522
- * @param items -
1523
- * The items to join.
1524
- *
1525
- * @returns
1526
- * A string that joins the items that are defined, separated by a space delimiter.
1527
- *
1528
- * @see
1529
- * {@link joinDefined} for more information and examples.
1530
- */ const cssJoinDefined = spaceJoinDefined;
1531
- /**
1532
- * Alias of joinList with a comma delimiter.
1533
- *
1534
- * @param items -
1535
- * The items to join.
1536
- *
1537
- * @returns
1538
- * A string that joins the items that are defined, separated by a comma delimiter.
1539
- *
1540
- * @see
1541
- * {@link joinDefined} for more information and examples.
1542
- */ const commaJoinDefined = joinDefined.bind(null, ",");
1543
- /**
1544
- * Alias of joinList with a semi-colon delimiter.
1545
- *
1546
- * @param items -
1547
- * The items to join.
1548
- *
1549
- * @returns
1550
- * A string that joins the items that are defined, separated by a semi-colon delimiter.
1551
- *
1552
- * @see
1553
- * {@link joinDefined} for more information and examples.
1554
- */ const semiColonJoinDefined = joinDefined.bind(null, ";");
1555
- /**
1556
- * Alias of joinList with a pipe delimiter.
1557
- *
1558
- * @param items -
1559
- * The items to join.
1560
- *
1561
- * @returns
1562
- * A string that joins the items that are defined, separated by a pipe delimiter.
1563
- *
1564
- * @see
1565
- * {@link joinDefined} for more information and examples.
1566
- */ const pipeJoinDefined = joinDefined.bind(null, "|");
1567
-
1568
- function _define_property$2(obj, key, value) {
1569
- if (key in obj) {
1570
- Object.defineProperty(obj, key, {
1571
- value: value,
1572
- enumerable: true,
1573
- configurable: true,
1574
- writable: true
1575
- });
1576
- } else {
1577
- obj[key] = value;
1578
- }
1579
- return obj;
1316
+ * Resolves the global object without referencing DOM globals so this can be
1317
+ * consumed in Node builds that do not include the `dom` lib.
1318
+ */ var $global = globalThis;
1319
+ //#endregion
1320
+ //#region src/join-defined/join-defined.mts
1321
+ /**
1322
+ * A set of parameters that can be used for a string join.
1323
+ *
1324
+ * Join lists can be a regular object, null, undefined, or a tuple where the
1325
+ * first item is the object to join, and the second item is a boolean that specifies
1326
+ * whether to include it if the value is truthy.
1327
+ *
1328
+ * @param T -
1329
+ * The type of data to join.
1330
+ */ /**
1331
+ * Similar to Array.join but filters out null and undefined items.
1332
+ *
1333
+ * @param delimiter -
1334
+ * The delimiter that separates the items.
1335
+ * @param items -
1336
+ * The items to join.
1337
+ * @param T -
1338
+ * The type of data to join.
1339
+ *
1340
+ * @returns
1341
+ * A string that joins the items that are defined, separated by delimiter.
1342
+ *
1343
+ * @example
1344
+ *
1345
+ * ```ts
1346
+ * // 'a b d'
1347
+ * const joinBySpace = joinDefined(' ', 'a', 'b', ['c', false], null, undefined, ['d', true]);
1348
+ * // (Empty String)
1349
+ * const joinEmpty = joinDefined('?');
1350
+ * ```
1351
+ */ function joinDefined(delimiter, ...items) {
1352
+ return items.map((item) => item instanceof Array ? item[1] ? item[0] : null : item).filter((item) => item != null).join(delimiter);
1580
1353
  }
1581
- class ZLazy {
1582
- initialized() {
1583
- return this._value != null;
1584
- }
1585
- async get() {
1586
- if (this._value == null) {
1587
- this._value = this._factory();
1588
- }
1589
- return this._value;
1590
- }
1591
- constructor(_factory){
1592
- _define_property$2(this, "_factory", void 0);
1593
- _define_property$2(this, "_value", void 0);
1594
- this._factory = _factory;
1595
- }
1596
- }
1597
-
1598
1354
  /**
1599
- * A specific set of possible values that need to be checked for requirements.
1600
- *
1601
- * @param T -
1602
- * The type of value that is being checked.
1603
- */ /**
1604
- * Requires a value to be non null.
1605
- *
1606
- * @param val -
1607
- * The value to require. This can be a promise
1608
- * that can return null or undefined in addition to the
1609
- * value.
1610
- * @param T -
1611
- * The type of value that is being checked.
1612
- *
1613
- * @returns
1614
- * This method returns val if it is not null
1615
- * or undefined, otherwise, an error is thrown.
1616
- *
1617
- * @throws
1618
- * An error if the value is null or undefined.
1619
- */ async function required(val) {
1620
- if (val == null) {
1621
- throw new Error("A required value was not provided");
1622
- }
1623
- const _val = await val;
1624
- if (_val == null) {
1625
- throw new Error("A required value was not provided");
1626
- }
1627
- return _val;
1355
+ * Alias to joinList with a space delimiter.
1356
+ *
1357
+ * @param items -
1358
+ * The items to join.
1359
+ *
1360
+ * @returns
1361
+ * A string that joins the items that are defined, separated by space delimiter.
1362
+ *
1363
+ * @see
1364
+ * {@link joinDefined} for more information and examples.
1365
+ */ var spaceJoinDefined = joinDefined.bind(null, " ");
1366
+ /**
1367
+ * Alias of spaceJoinList.
1368
+ *
1369
+ * @param items -
1370
+ * The items to join.
1371
+ *
1372
+ * @returns
1373
+ * A string that joins the items that are defined, separated by a space delimiter.
1374
+ *
1375
+ * @see
1376
+ * {@link joinDefined} for more information and examples.
1377
+ */ var cssJoinDefined = spaceJoinDefined;
1378
+ /**
1379
+ * Alias of joinList with a comma delimiter.
1380
+ *
1381
+ * @param items -
1382
+ * The items to join.
1383
+ *
1384
+ * @returns
1385
+ * A string that joins the items that are defined, separated by a comma delimiter.
1386
+ *
1387
+ * @see
1388
+ * {@link joinDefined} for more information and examples.
1389
+ */ var commaJoinDefined = joinDefined.bind(null, ",");
1390
+ /**
1391
+ * Alias of joinList with a semi-colon delimiter.
1392
+ *
1393
+ * @param items -
1394
+ * The items to join.
1395
+ *
1396
+ * @returns
1397
+ * A string that joins the items that are defined, separated by a semi-colon delimiter.
1398
+ *
1399
+ * @see
1400
+ * {@link joinDefined} for more information and examples.
1401
+ */ var semiColonJoinDefined = joinDefined.bind(null, ";");
1402
+ /**
1403
+ * Alias of joinList with a pipe delimiter.
1404
+ *
1405
+ * @param items -
1406
+ * The items to join.
1407
+ *
1408
+ * @returns
1409
+ * A string that joins the items that are defined, separated by a pipe delimiter.
1410
+ *
1411
+ * @see
1412
+ * {@link joinDefined} for more information and examples.
1413
+ */ var pipeJoinDefined = joinDefined.bind(null, "|");
1414
+ //#endregion
1415
+ //#region src/lazy/lazy.mts
1416
+ var ZLazy = class {
1417
+ _factory;
1418
+ _value;
1419
+ constructor(_factory) {
1420
+ this._factory = _factory;
1421
+ }
1422
+ initialized() {
1423
+ return this._value != null;
1424
+ }
1425
+ async get() {
1426
+ if (this._value == null) this._value = this._factory();
1427
+ return this._value;
1428
+ }
1429
+ };
1430
+ //#endregion
1431
+ //#region src/obligation/obligation.mts
1432
+ /**
1433
+ * A specific set of possible values that need to be checked for requirements.
1434
+ *
1435
+ * @param T -
1436
+ * The type of value that is being checked.
1437
+ */ /**
1438
+ * Requires a value to be non null.
1439
+ *
1440
+ * @param val -
1441
+ * The value to require. This can be a promise
1442
+ * that can return null or undefined in addition to the
1443
+ * value.
1444
+ * @param T -
1445
+ * The type of value that is being checked.
1446
+ *
1447
+ * @returns
1448
+ * This method returns val if it is not null
1449
+ * or undefined, otherwise, an error is thrown.
1450
+ *
1451
+ * @throws
1452
+ * An error if the value is null or undefined.
1453
+ */ async function required(val) {
1454
+ if (val == null) throw new Error("A required value was not provided");
1455
+ const _val = await val;
1456
+ if (_val == null) throw new Error("A required value was not provided");
1457
+ return _val;
1628
1458
  }
1629
1459
  /**
1630
- * Allows a value to be null or undefined and has a fallback.
1631
- *
1632
- * @param val -
1633
- * The value to check. This can be a promise
1634
- * that can return null or undefined in addition to the
1635
- * value.
1636
- * @param fallback -
1637
- * The fallback value in the case that val is
1638
- * null or undefined.
1639
- * @param T -
1640
- * The type of value that is being checked.
1641
- *
1642
- * @returns
1643
- * This method returns val if it is not null
1644
- * or undefined, otherwise, the fallback is returned.
1645
- * If val is a promise and rejects, then fallback is
1646
- * also returned.
1647
- */ async function optional(val, fallback = null) {
1648
- if (val == null) {
1649
- return fallback;
1650
- }
1651
- try {
1652
- const _val = await val;
1653
- return _val == null ? fallback : _val;
1654
- } catch {
1655
- return fallback;
1656
- }
1460
+ * Allows a value to be null or undefined and has a fallback.
1461
+ *
1462
+ * @param val -
1463
+ * The value to check. This can be a promise
1464
+ * that can return null or undefined in addition to the
1465
+ * value.
1466
+ * @param fallback -
1467
+ * The fallback value in the case that val is
1468
+ * null or undefined.
1469
+ * @param T -
1470
+ * The type of value that is being checked.
1471
+ *
1472
+ * @returns
1473
+ * This method returns val if it is not null
1474
+ * or undefined, otherwise, the fallback is returned.
1475
+ * If val is a promise and rejects, then fallback is
1476
+ * also returned.
1477
+ */ async function optional(val, fallback = null) {
1478
+ if (val == null) return fallback;
1479
+ try {
1480
+ const _val = await val;
1481
+ return _val == null ? fallback : _val;
1482
+ } catch {
1483
+ return fallback;
1484
+ }
1657
1485
  }
1658
-
1659
- /**
1660
- * Represents a direction orientation.
1661
- */ var ZOrientation = /*#__PURE__*/ function(ZOrientation) {
1662
- /**
1663
- * Horizontal orientation.
1664
- *
1665
- * This type of orientation is a row
1666
- * style orientation or flex-row orientation.
1667
- */ ZOrientation["Horizontal"] = "horizontal";
1668
- /**
1669
- * Vertical orientation.
1670
- *
1671
- * This type of orientation is a column
1672
- * style orientation or block orientation.
1673
- */ ZOrientation["Vertical"] = "vertical";
1674
- return ZOrientation;
1486
+ //#endregion
1487
+ //#region src/orientation/orientation.mts
1488
+ /**
1489
+ * Represents a direction orientation.
1490
+ */ var ZOrientation = /* @__PURE__ */ function(ZOrientation) {
1491
+ /**
1492
+ * Horizontal orientation.
1493
+ *
1494
+ * This type of orientation is a row
1495
+ * style orientation or flex-row orientation.
1496
+ */ ZOrientation["Horizontal"] = "horizontal";
1497
+ /**
1498
+ * Vertical orientation.
1499
+ *
1500
+ * This type of orientation is a column
1501
+ * style orientation or block orientation.
1502
+ */ ZOrientation["Vertical"] = "vertical";
1503
+ return ZOrientation;
1675
1504
  }({});
1676
-
1677
- /**
1678
- * Peels a candidate string from the start of a string and splits it into two segments.
1679
- *
1680
- * @param str -
1681
- * The string to peel from.
1682
- * @param candidates -
1683
- * The candidate list of values to peel from str.
1684
- *
1685
- * @returns
1686
- * A tuple where the first item is the peeled string and
1687
- * the second item is the remainder of the string. If the string
1688
- * does not start with any given candidates, then the first
1689
- * item will be null and the second item will be str.
1690
- */ function peel(str, candidates) {
1691
- for (const check of candidates){
1692
- if (str.startsWith(check)) {
1693
- return [
1694
- str.substring(0, check.length),
1695
- str.substring(check.length)
1696
- ];
1697
- }
1698
- }
1699
- return [
1700
- null,
1701
- str
1702
- ];
1505
+ //#endregion
1506
+ //#region src/peel/peel.mts
1507
+ /**
1508
+ * Peels a candidate string from the start of a string and splits it into two segments.
1509
+ *
1510
+ * @param str -
1511
+ * The string to peel from.
1512
+ * @param candidates -
1513
+ * The candidate list of values to peel from str.
1514
+ *
1515
+ * @returns
1516
+ * A tuple where the first item is the peeled string and
1517
+ * the second item is the remainder of the string. If the string
1518
+ * does not start with any given candidates, then the first
1519
+ * item will be null and the second item will be str.
1520
+ */ function peel(str, candidates) {
1521
+ for (const check of candidates) if (str.startsWith(check)) return [str.substring(0, check.length), str.substring(check.length)];
1522
+ return [null, str];
1703
1523
  }
1704
1524
  /**
1705
- * Peels the values between an opening string set and a closing string set.
1706
- *
1707
- * The actual value will handle issues with internal opening and closing brackets
1708
- *
1709
- * @example
1710
- *
1711
- * ```ts
1712
- * const [peeled, rest] = peelBetween('[a, b, [c1, c2],[d]] other', '[' ']');
1713
- *
1714
- * // Outputs 'a, b, [c1, c2], [d]'
1715
- * console.log(peeled);
1716
- *
1717
- * // Outputs ' other' - white space is included'
1718
- * console.log(rest);
1719
- * ```
1720
- *
1721
- * @param str -
1722
- * The string to peel between.
1723
- * @param open -
1724
- * The opening string. This will test
1725
- * at the start of str.
1726
- * @param close -
1727
- * The closing string. This can be anywhere
1728
- * in the str. If this is equal to open, then
1729
- * the open string is removed from the start of the
1730
- * string and the rest of the string would be returned.
1731
- *
1732
- * @returns
1733
- * A tuple where the first argument is string that was found between
1734
- * the opening and closing bracket. Returns null if no string could
1735
- * be found between an open and close pair. The second argument will
1736
- * be the remaining text of the string, including whitespace.
1737
- */ function peelBetween(str, open, close) {
1738
- if (!str.startsWith(open)) {
1739
- return [
1740
- null,
1741
- str
1742
- ];
1743
- }
1744
- let stack = 1;
1745
- const _str = str.substring(open.length);
1746
- for(let i = 0; i < _str.length; ++i){
1747
- if (_str.startsWith(open, i)) {
1748
- stack += 1;
1749
- i += open.length - 1;
1750
- continue;
1751
- }
1752
- if (_str.startsWith(close, i)) {
1753
- stack -= 1;
1754
- if (stack === 0) {
1755
- return [
1756
- _str.substring(0, i),
1757
- _str.substring(i + close.length)
1758
- ];
1759
- }
1760
- i += close.length - 1;
1761
- }
1762
- }
1763
- return [
1764
- null,
1765
- str
1766
- ];
1525
+ * Peels the values between an opening string set and a closing string set.
1526
+ *
1527
+ * The actual value will handle issues with internal opening and closing brackets
1528
+ *
1529
+ * @example
1530
+ *
1531
+ * ```ts
1532
+ * const [peeled, rest] = peelBetween('[a, b, [c1, c2],[d]] other', '[' ']');
1533
+ *
1534
+ * // Outputs 'a, b, [c1, c2], [d]'
1535
+ * console.log(peeled);
1536
+ *
1537
+ * // Outputs ' other' - white space is included'
1538
+ * console.log(rest);
1539
+ * ```
1540
+ *
1541
+ * @param str -
1542
+ * The string to peel between.
1543
+ * @param open -
1544
+ * The opening string. This will test
1545
+ * at the start of str.
1546
+ * @param close -
1547
+ * The closing string. This can be anywhere
1548
+ * in the str. If this is equal to open, then
1549
+ * the open string is removed from the start of the
1550
+ * string and the rest of the string would be returned.
1551
+ *
1552
+ * @returns
1553
+ * A tuple where the first argument is string that was found between
1554
+ * the opening and closing bracket. Returns null if no string could
1555
+ * be found between an open and close pair. The second argument will
1556
+ * be the remaining text of the string, including whitespace.
1557
+ */ function peelBetween(str, open, close) {
1558
+ if (!str.startsWith(open)) return [null, str];
1559
+ let stack = 1;
1560
+ const _str = str.substring(open.length);
1561
+ for (let i = 0; i < _str.length; ++i) {
1562
+ if (_str.startsWith(open, i)) {
1563
+ stack += 1;
1564
+ i += open.length - 1;
1565
+ continue;
1566
+ }
1567
+ if (_str.startsWith(close, i)) {
1568
+ stack -= 1;
1569
+ if (stack === 0) return [_str.substring(0, i), _str.substring(i + close.length)];
1570
+ i += close.length - 1;
1571
+ }
1572
+ }
1573
+ return [null, str];
1767
1574
  }
1768
-
1769
- /**
1770
- * A function that reduces an object to keys and values that match a predicate.
1771
- *
1772
- * @param predicate -
1773
- * The predicate to match the key and value against.
1774
- * @param target -
1775
- * The object to reduce.
1776
- *
1777
- * @returns
1778
- * A reduced object that only contains key-value pairs that match
1779
- * the predicate.
1780
- */ function pickBy(predicate, target) {
1781
- const keys = Object.keys(target);
1782
- const reduced = {};
1783
- keys.forEach((key)=>{
1784
- const value = target[key];
1785
- if (predicate(key, value)) {
1786
- reduced[key] = value;
1787
- }
1788
- });
1789
- return reduced;
1575
+ //#endregion
1576
+ //#region src/pick/pick.mts
1577
+ /**
1578
+ * A function that reduces an object to keys and values that match a predicate.
1579
+ *
1580
+ * @param predicate -
1581
+ * The predicate to match the key and value against.
1582
+ * @param target -
1583
+ * The object to reduce.
1584
+ *
1585
+ * @returns
1586
+ * A reduced object that only contains key-value pairs that match
1587
+ * the predicate.
1588
+ */ function pickBy(predicate, target) {
1589
+ const keys = Object.keys(target);
1590
+ const reduced = {};
1591
+ keys.forEach((key) => {
1592
+ const value = target[key];
1593
+ if (predicate(key, value)) reduced[key] = value;
1594
+ });
1595
+ return reduced;
1790
1596
  }
1791
1597
  /**
1792
- * An alias to pickBy with a predicate of (_, v) =&gt; v != null.
1793
- *
1794
- * @param target -
1795
- * The target object to reduce.
1796
- *
1797
- * @returns
1798
- * The reduced object.
1799
- */ function pickDefined(target) {
1800
- return pickBy((_, v)=>v != null, target);
1598
+ * An alias to pickBy with a predicate of (_, v) =&gt; v != null.
1599
+ *
1600
+ * @param target -
1601
+ * The target object to reduce.
1602
+ *
1603
+ * @returns
1604
+ * The reduced object.
1605
+ */ function pickDefined(target) {
1606
+ return pickBy((_, v) => v != null, target);
1801
1607
  }
1802
1608
  /**
1803
- * An alias to pickBy((k) =&gt; k.startsWith('data-')).
1804
- *
1805
- * @param target -
1806
- * The target object to reduce.
1807
- *
1808
- * @returns
1809
- * The reduced object.
1810
- */ function pickDataAttributes(target) {
1811
- return pickBy((k)=>String(k).startsWith("data-"), target);
1609
+ * An alias to pickBy((k) =&gt; k.startsWith('data-')).
1610
+ *
1611
+ * @param target -
1612
+ * The target object to reduce.
1613
+ *
1614
+ * @returns
1615
+ * The reduced object.
1616
+ */ function pickDataAttributes(target) {
1617
+ return pickBy((k) => String(k).startsWith("data-"), target);
1812
1618
  }
1813
1619
  /**
1814
- * An alias to pickBy((k) =&gt; k.startsWith('on')).
1815
- *
1816
- * @param target -
1817
- * The target object to reduce.
1818
- *
1819
- * @returns
1820
- * The reduced object.
1821
- */ function pickEvents(target) {
1822
- return pickBy((k)=>String(k).startsWith("on"), target);
1620
+ * An alias to pickBy((k) =&gt; k.startsWith('on')).
1621
+ *
1622
+ * @param target -
1623
+ * The target object to reduce.
1624
+ *
1625
+ * @returns
1626
+ * The reduced object.
1627
+ */ function pickEvents(target) {
1628
+ return pickBy((k) => String(k).startsWith("on"), target);
1823
1629
  }
1824
-
1630
+ //#endregion
1631
+ //#region src/purge/purge.mts
1825
1632
  function purge(obj, property) {
1826
- if (obj[property] === undefined) {
1827
- delete obj[property];
1828
- }
1633
+ if (obj[property] === void 0) delete obj[property];
1829
1634
  }
1830
-
1831
- function _define_property$1(obj, key, value) {
1832
- if (key in obj) {
1833
- Object.defineProperty(obj, key, {
1834
- value: value,
1835
- enumerable: true,
1836
- configurable: true,
1837
- writable: true
1838
- });
1839
- } else {
1840
- obj[key] = value;
1841
- }
1842
- return obj;
1843
- }
1844
- /**
1845
- * A deserializer that deserializes a JSON string.
1846
- */ class ZDeserializeJson {
1847
- deserialize(candidate) {
1848
- const parsed = JSON.parse(candidate);
1849
- if (this._schema && !this._schema(parsed)) {
1850
- throw new Error("The parsed JSON does not conform to the given schema requirement");
1851
- }
1852
- return parsed;
1853
- }
1854
- constructor(_schema){
1855
- _define_property$1(this, "_schema", void 0);
1856
- this._schema = _schema;
1857
- }
1858
- }
1859
-
1860
- function _define_property(obj, key, value) {
1861
- if (key in obj) {
1862
- Object.defineProperty(obj, key, {
1863
- value: value,
1864
- enumerable: true,
1865
- configurable: true,
1866
- writable: true
1867
- });
1868
- } else {
1869
- obj[key] = value;
1870
- }
1871
- return obj;
1872
- }
1873
- /**
1874
- * A deserializer that attempts to deserialize multiple times through a series of supported languages.
1875
- *
1876
- * @param T -
1877
- * The type of data to deserialize.
1878
- * @param S -
1879
- * The input type
1880
- */ class ZDeserializeTry {
1881
- deserialize(candidate) {
1882
- const errors = [];
1883
- for (const child of this._children){
1884
- try {
1885
- return child.deserialize(candidate);
1886
- } catch (e) {
1887
- errors.push(e.message);
1888
- }
1889
- }
1890
- const msg = `Unable to deserialize candidate, ${candidate}.`;
1891
- errors.splice(0, 0, msg);
1892
- throw new Error(errors.join("\n\n"));
1893
- }
1894
- /**
1895
- * Initializes a new instance of this object.
1896
- *
1897
- * @param _children -
1898
- * The list of deserializer objects to try on a specific candidate.
1899
- * The first deserializer to succeed will return the target object.
1900
- * If no deserializer is able to deserialize the candidate, then an
1901
- * error is throw with a mapping of serialization errors between each
1902
- * deserializer.
1903
- */ constructor(_children){
1904
- _define_property(this, "_children", void 0);
1905
- this._children = _children;
1906
- }
1907
- }
1908
-
1909
- /**
1910
- * Represents a serializer that serializes anything to a JSON string.
1911
- */ class ZSerializeJson {
1912
- serialize(candidate) {
1913
- return JSON.stringify(candidate, undefined, 2);
1914
- }
1915
- }
1916
-
1917
- /**
1918
- * Represents a setter function for when you want to set a single value,
1919
- * but you have an array instead.
1920
- *
1921
- * This is useful when you want to support lists of items, but you need
1922
- * backwards compatibility for setting a single item. This is primarily meant
1923
- * to be use with bind to construct a new method setter that takes an array
1924
- * and forwards it to a setter method which will accept a single value of the
1925
- * first item in the target value.
1926
- *
1927
- * @param setValue -
1928
- * The setter function that takes a single value. This will receive
1929
- * the first item of the value list.
1930
- * @param fallback -
1931
- * The fallback value in the case that there are no values.
1932
- * @param value -
1933
- * The value list to retrieve the first item from.
1934
- * @param T -
1935
- * The type of data that the array holds.
1936
- *
1937
- * @example
1938
- *
1939
- * ```ts
1940
- * // An example of a react component that needs a value of an array, but you only care about a single selection.
1941
- * const [value, setValue] = useState<TypesOfPie>();
1942
- * const _values = useMemo(() => value ? [value] : [], [value]);
1943
- * const _setValues = setFirst.bind(null, setValue, undefined);
1944
- *
1945
- * return <ComponentWithMultiSelectSupport values={_values} onValuesChange={_setValues} />
1946
- * ```
1947
- */ function setFirst(setValue, fallback, value) {
1948
- const _value = value?.length ? value[0] : fallback;
1949
- setValue(_value);
1635
+ //#endregion
1636
+ //#region src/serialize/deserialize-json.mts
1637
+ /**
1638
+ * A deserializer that deserializes a JSON string.
1639
+ */ var ZDeserializeJson = class {
1640
+ _schema;
1641
+ constructor(_schema) {
1642
+ this._schema = _schema;
1643
+ }
1644
+ deserialize(candidate) {
1645
+ const parsed = JSON.parse(candidate);
1646
+ if (this._schema && !this._schema(parsed)) throw new Error("The parsed JSON does not conform to the given schema requirement");
1647
+ return parsed;
1648
+ }
1649
+ };
1650
+ //#endregion
1651
+ //#region src/serialize/deserialize-try.mts
1652
+ /**
1653
+ * A deserializer that attempts to deserialize multiple times through a series of supported languages.
1654
+ *
1655
+ * @param T -
1656
+ * The type of data to deserialize.
1657
+ * @param S -
1658
+ * The input type
1659
+ */ var ZDeserializeTry = class {
1660
+ _children;
1661
+ /**
1662
+ * Initializes a new instance of this object.
1663
+ *
1664
+ * @param _children -
1665
+ * The list of deserializer objects to try on a specific candidate.
1666
+ * The first deserializer to succeed will return the target object.
1667
+ * If no deserializer is able to deserialize the candidate, then an
1668
+ * error is throw with a mapping of serialization errors between each
1669
+ * deserializer.
1670
+ */ constructor(_children) {
1671
+ this._children = _children;
1672
+ }
1673
+ deserialize(candidate) {
1674
+ const errors = [];
1675
+ for (const child of this._children) try {
1676
+ return child.deserialize(candidate);
1677
+ } catch (e) {
1678
+ errors.push(e.message);
1679
+ }
1680
+ const msg = `Unable to deserialize candidate, ${JSON.stringify(candidate)}.`;
1681
+ errors.splice(0, 0, msg);
1682
+ throw new Error(errors.join("\n\n"));
1683
+ }
1684
+ };
1685
+ //#endregion
1686
+ //#region src/serialize/serialize-json.mts
1687
+ /**
1688
+ * Represents a serializer that serializes anything to a JSON string.
1689
+ */ var ZSerializeJson = class {
1690
+ serialize(candidate) {
1691
+ return JSON.stringify(candidate, void 0, 2);
1692
+ }
1693
+ };
1694
+ //#endregion
1695
+ //#region src/set-first/set-first.mts
1696
+ /**
1697
+ * Represents a setter function for when you want to set a single value,
1698
+ * but you have an array instead.
1699
+ *
1700
+ * This is useful when you want to support lists of items, but you need
1701
+ * backwards compatibility for setting a single item. This is primarily meant
1702
+ * to be use with bind to construct a new method setter that takes an array
1703
+ * and forwards it to a setter method which will accept a single value of the
1704
+ * first item in the target value.
1705
+ *
1706
+ * @param setValue -
1707
+ * The setter function that takes a single value. This will receive
1708
+ * the first item of the value list.
1709
+ * @param fallback -
1710
+ * The fallback value in the case that there are no values.
1711
+ * @param value -
1712
+ * The value list to retrieve the first item from.
1713
+ * @param T -
1714
+ * The type of data that the array holds.
1715
+ *
1716
+ * @example
1717
+ *
1718
+ * ```ts
1719
+ * // An example of a react component that needs a value of an array, but you only care about a single selection.
1720
+ * const [value, setValue] = useState<TypesOfPie>();
1721
+ * const _values = useMemo(() => value ? [value] : [], [value]);
1722
+ * const _setValues = setFirst.bind(null, setValue, undefined);
1723
+ *
1724
+ * return <ComponentWithMultiSelectSupport values={_values} onValuesChange={_setValues} />
1725
+ * ```
1726
+ */ function setFirst(setValue, fallback, value) {
1727
+ setValue(value?.length ? value[0] : fallback);
1950
1728
  }
1951
-
1952
- /**
1953
- * Halts the current thread to invoke an event loop.
1954
- *
1955
- * @param ms -
1956
- * The total number of milliseconds to sleep.
1957
- *
1958
- * @returns
1959
- * A promise that resolves after ms milliseconds.
1960
- */ /**
1961
- * Halts the current thread to invoke an event loop.
1962
- *
1963
- * @param ms -
1964
- * The total number of milliseconds to sleep.
1965
- * @param T -
1966
- * The type of value that will be resolved.
1967
- *
1968
- * @returns
1969
- * A promise that resolves with val after ms milliseconds.
1970
- */ function sleep(ms = 0, val = undefined) {
1971
- return new Promise((resolve)=>setTimeout(()=>resolve(val), ms));
1729
+ //#endregion
1730
+ //#region src/sleep/sleep.mts
1731
+ /**
1732
+ * Halts the current thread to invoke an event loop.
1733
+ *
1734
+ * @param ms -
1735
+ * The total number of milliseconds to sleep.
1736
+ *
1737
+ * @returns
1738
+ * A promise that resolves after ms milliseconds.
1739
+ */ /**
1740
+ * Halts the current thread to invoke an event loop.
1741
+ *
1742
+ * @param ms -
1743
+ * The total number of milliseconds to sleep.
1744
+ * @param T -
1745
+ * The type of value that will be resolved.
1746
+ *
1747
+ * @returns
1748
+ * A promise that resolves with val after ms milliseconds.
1749
+ */ function sleep(ms = 0, val = void 0) {
1750
+ return new Promise((resolve) => setTimeout(() => resolve(val), ms));
1972
1751
  }
1973
-
1974
- /**
1975
- * This is just a method that allows you to tag an interpolation
1976
- * string as a syntax language.
1977
- *
1978
- * This is useful with IDE extensions that can detect the language
1979
- * and do the syntax highlighting for you.
1980
- *
1981
- * @param strings -
1982
- * The string breaks for interpolation.
1983
- * @param expressions -
1984
- * The equivalent expressions that break apart
1985
- * the single string literal.
1986
- *
1987
- * @returns
1988
- * The compiled string literal. This is no different
1989
- * than letting native JavaScript do it for you.
1990
- *
1991
- * @example
1992
- *
1993
- * ```ts
1994
- * const html = tag;
1995
- * const css = tag;
1996
- *
1997
- * const $html = html`
1998
- * <div>Some IDE extensions will highlight this as html</div>
1999
- * `
2000
- *
2001
- * const $css = css`
2002
- * button {
2003
- * display: grid;
2004
- * }
2005
- * `
2006
- * ```
2007
- */ function tag(strings, ...expressions) {
2008
- let [result] = strings;
2009
- for(let i = 1, l = strings.length; i < l; i++){
2010
- result += expressions[i - 1];
2011
- result += strings[i];
2012
- }
2013
- return result;
1752
+ //#endregion
1753
+ //#region src/tag/tag.mts
1754
+ /**
1755
+ * This is just a method that allows you to tag an interpolation
1756
+ * string as a syntax language.
1757
+ *
1758
+ * This is useful with IDE extensions that can detect the language
1759
+ * and do the syntax highlighting for you.
1760
+ *
1761
+ * @param strings -
1762
+ * The string breaks for interpolation.
1763
+ * @param expressions -
1764
+ * The equivalent expressions that break apart
1765
+ * the single string literal.
1766
+ *
1767
+ * @returns
1768
+ * The compiled string literal. This is no different
1769
+ * than letting native JavaScript do it for you.
1770
+ *
1771
+ * @example
1772
+ *
1773
+ * ```ts
1774
+ * const html = tag;
1775
+ * const css = tag;
1776
+ *
1777
+ * const $html = html`
1778
+ * <div>Some IDE extensions will highlight this as html</div>
1779
+ * `
1780
+ *
1781
+ * const $css = css`
1782
+ * button {
1783
+ * display: grid;
1784
+ * }
1785
+ * `
1786
+ * ```
1787
+ */ function tag(strings, ...expressions) {
1788
+ let [result] = strings;
1789
+ for (let i = 1, l = strings.length; i < l; i++) {
1790
+ result += String(expressions[i - 1]);
1791
+ result += strings[i];
1792
+ }
1793
+ return result;
2014
1794
  }
2015
1795
  /**
2016
- * An alias for {@link tag}.
2017
- *
2018
- * Some {@link https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html | IDE extensions will detect the string}
2019
- * interpolation as html when using this tag.
2020
- */ const html = tag;
2021
- /**
2022
- * An alias for {@link tag}.
2023
- *
2024
- * Some {@link https://marketplace.visualstudio.com/items?itemName=bashmish.es6-string-css | IDE extensions will detect the string}
2025
- * interpolation as css when using this tag.
2026
- */ const css = tag;
2027
- /**
2028
- * An alias for {@link tag}.
2029
- *
2030
- * Some {@link https://marketplace.visualstudio.com/items?itemName=zjcompt.es6-string-javascript | IDE extensions will detect the string}
2031
- * interpolation as javascript when using this tag.
2032
- */ const js = tag;
2033
- /**
2034
- * See {@link js}
2035
- */ const javascript = tag;
2036
- /**
2037
- * An alias for {@link tag}.
2038
- *
2039
- * Some {@link https://marketplace.visualstudio.com/items?itemName=jeoht.es6-string-markdown | IDE extensions will detect the string}
2040
- * interpolation as markdown when using this tag.
2041
- */ const md = tag;
2042
- /**
2043
- * See {@link md}
2044
- */ const markdown = tag;
2045
- /**
2046
- * An alias for {@link tag}.
2047
- *
2048
- * Some {@link https://marketplace.visualstudio.com/items?itemName=HoodieCollin.es6-string-typescript | IDE extensions will detect the string}
2049
- * interpolation as typescript when using this tag.
2050
- */ const ts = tag;
2051
- /**
2052
- * See {@link ts}
2053
- */ const typescript = tag;
2054
- /**
2055
- * An alias for {@link tag}.
2056
- */ const sh = tag;
2057
- /**
2058
- * An alias for {@link tag}.
2059
- */ const bash = tag;
2060
- /**
2061
- * An alias for {@link tag}.
2062
- */ const zsh = tag;
2063
-
2064
- /**
2065
- * Invokes the candidate function and returns undefined if an error is thrown from it.
2066
- *
2067
- * @param candidate -
2068
- * The candidate function to run.
2069
- *
2070
- * @returns
2071
- * The result from candidate. Returns undefined if candidate throws an Error.
2072
- */ /**
2073
- * Invokes the candidate function and returns fallback if an error is thrown from it.
2074
- *
2075
- * @param candidate -
2076
- * The candidate function to run.
2077
- * @param fallback -
2078
- * The fallback value to return if candidate throws an error.
2079
- *
2080
- * @returns
2081
- * The result from candidate. Returns fallback if candidate throws an Error.
2082
- * If no fallback value is provided, then undefined is returned.
2083
- */ function tryFallback(candidate, fallback) {
2084
- try {
2085
- return candidate();
2086
- } catch {
2087
- return fallback;
2088
- }
1796
+ * An alias for {@link tag}.
1797
+ *
1798
+ * Some {@link https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html | IDE extensions will detect the string}
1799
+ * interpolation as html when using this tag.
1800
+ */ var html = tag;
1801
+ /**
1802
+ * An alias for {@link tag}.
1803
+ *
1804
+ * Some {@link https://marketplace.visualstudio.com/items?itemName=bashmish.es6-string-css | IDE extensions will detect the string}
1805
+ * interpolation as css when using this tag.
1806
+ */ var css = tag;
1807
+ /**
1808
+ * An alias for {@link tag}.
1809
+ *
1810
+ * Some {@link https://marketplace.visualstudio.com/items?itemName=zjcompt.es6-string-javascript | IDE extensions will detect the string}
1811
+ * interpolation as javascript when using this tag.
1812
+ */ var js = tag;
1813
+ /**
1814
+ * See {@link js}
1815
+ */ var javascript = tag;
1816
+ /**
1817
+ * An alias for {@link tag}.
1818
+ *
1819
+ * Some {@link https://marketplace.visualstudio.com/items?itemName=jeoht.es6-string-markdown | IDE extensions will detect the string}
1820
+ * interpolation as markdown when using this tag.
1821
+ */ var md = tag;
1822
+ /**
1823
+ * See {@link md}
1824
+ */ var markdown = tag;
1825
+ /**
1826
+ * An alias for {@link tag}.
1827
+ *
1828
+ * Some {@link https://marketplace.visualstudio.com/items?itemName=HoodieCollin.es6-string-typescript | IDE extensions will detect the string}
1829
+ * interpolation as typescript when using this tag.
1830
+ */ var ts = tag;
1831
+ /**
1832
+ * See {@link ts}
1833
+ */ var typescript = tag;
1834
+ /**
1835
+ * An alias for {@link tag}.
1836
+ */ var sh = tag;
1837
+ /**
1838
+ * An alias for {@link tag}.
1839
+ */ var bash = tag;
1840
+ /**
1841
+ * An alias for {@link tag}.
1842
+ */ var zsh = tag;
1843
+ //#endregion
1844
+ //#region src/try/try-fallback.mts
1845
+ /**
1846
+ * Invokes the candidate function and returns undefined if an error is thrown from it.
1847
+ *
1848
+ * @param candidate -
1849
+ * The candidate function to run.
1850
+ *
1851
+ * @returns
1852
+ * The result from candidate. Returns undefined if candidate throws an Error.
1853
+ */ /**
1854
+ * Invokes the candidate function and returns fallback if an error is thrown from it.
1855
+ *
1856
+ * @param candidate -
1857
+ * The candidate function to run.
1858
+ * @param fallback -
1859
+ * The fallback value to return if candidate throws an error.
1860
+ *
1861
+ * @returns
1862
+ * The result from candidate. Returns fallback if candidate throws an Error.
1863
+ * If no fallback value is provided, then undefined is returned.
1864
+ */ function tryFallback(candidate, fallback) {
1865
+ try {
1866
+ return candidate();
1867
+ } catch {
1868
+ return fallback;
1869
+ }
2089
1870
  }
2090
1871
  /**
2091
- * Invokes the candidate function and returns undefined if an rejected promise is returned from it.
2092
- *
2093
- * @param candidate -
2094
- * The candidate function to run.
2095
- * @param fallback -
2096
- * The optional fallback value to return if the candidate throws an Error.
2097
- *
2098
- * @returns
2099
- * A promise that resolves with the result from candidate or fallback
2100
- * if candidate returns a rejected promise. Resolves with undefined
2101
- * if no fallback is provided.
2102
- */ async function tryFallbackAsync(candidate, fallback) {
2103
- try {
2104
- return await candidate();
2105
- } catch {
2106
- return fallback;
2107
- }
1872
+ * Invokes the candidate function and returns undefined if an rejected promise is returned from it.
1873
+ *
1874
+ * @param candidate -
1875
+ * The candidate function to run.
1876
+ * @param fallback -
1877
+ * The optional fallback value to return if the candidate throws an Error.
1878
+ *
1879
+ * @returns
1880
+ * A promise that resolves with the result from candidate or fallback
1881
+ * if candidate returns a rejected promise. Resolves with undefined
1882
+ * if no fallback is provided.
1883
+ */ async function tryFallbackAsync(candidate, fallback) {
1884
+ try {
1885
+ return await candidate();
1886
+ } catch {
1887
+ return fallback;
1888
+ }
2108
1889
  }
2109
-
2110
- /**
2111
- * Attempts to parse the string buffer as json.
2112
- *
2113
- * This is similar to JSON.parse, but instead of throwing
2114
- * an error, it returns the fallback.
2115
- *
2116
- * @param buffer -
2117
- * The string buffer that may be json.
2118
- * @param fallback -
2119
- * The fallback value in the case that buffer
2120
- * cannot be parsed. Note that parsing the text
2121
- * "null" will return null instead of the fallback.
2122
- * The default value for this is null.
2123
- *
2124
- * @returns
2125
- * The parsed value of the buffer when parsed as JSON. If
2126
- * buffer is null, undefined, or does not represent valid
2127
- * JSON, then the fallback is returned.
2128
- */ function tryJsonParse(buffer, fallback = null) {
2129
- if (buffer == null) {
2130
- return fallback;
2131
- }
2132
- // This is not really necessary because it is handled in the
2133
- // JSON.parse method, but this avoids parsing random binary data.
2134
- // If someone tries to read a buffer that's 300MB, there's no point
2135
- // trying to parse it if it's just random binary data. This can
2136
- // still happen if the first binary character is { or [, but
2137
- // most situations won't have this happen.
2138
- const [firstChar] = buffer;
2139
- if (firstChar !== "{" && firstChar !== "[") {
2140
- return fallback;
2141
- }
2142
- return tryFallback(()=>JSON.parse(buffer), fallback);
1890
+ //#endregion
1891
+ //#region src/try/try-json-parse.mts
1892
+ /**
1893
+ * Attempts to parse the string buffer as json.
1894
+ *
1895
+ * This is similar to JSON.parse, but instead of throwing
1896
+ * an error, it returns the fallback.
1897
+ *
1898
+ * @param buffer -
1899
+ * The string buffer that may be json.
1900
+ * @param fallback -
1901
+ * The fallback value in the case that buffer
1902
+ * cannot be parsed. Note that parsing the text
1903
+ * "null" will return null instead of the fallback.
1904
+ * The default value for this is null.
1905
+ *
1906
+ * @returns
1907
+ * The parsed value of the buffer when parsed as JSON. If
1908
+ * buffer is null, undefined, or does not represent valid
1909
+ * JSON, then the fallback is returned.
1910
+ */ function tryJsonParse(buffer, fallback = null) {
1911
+ if (buffer == null) return fallback;
1912
+ const [firstChar] = buffer;
1913
+ if (firstChar !== "{" && firstChar !== "[") return fallback;
1914
+ return tryFallback(() => JSON.parse(buffer), fallback);
2143
1915
  }
2144
-
1916
+ //#endregion
2145
1917
  export { $global, ZAssert, ZDateFormats, ZDeserializeJson, ZDeserializeTry, ZEnumInfoBuilder, ZHorizontalAnchor, ZLazy, ZOrientation, ZQuadrilateralBuilder, ZQuadrilateralCornersBuilder, ZRectangle, ZSerializeJson, ZVerticalAnchor, bash, castEnum, castExtension, castNumber, commaJoinDefined, countBuckets, createError, createGuid, css, cssJoinDefined, culture, cultures, detokenize, firstDefined, firstTruthy, firstWhere, formatDateTime, gib, gibibytes, guessDateTime, html, isEmptyObject, isEnum, javascript, joinDefined, js, kib, kibibytes, markdown, md, mebibytes, mib, optional, parseDateTime, pebibytes, peel, peelBetween, pib, pickBy, pickDataAttributes, pickDefined, pickEvents, pipeJoinDefined, purge, required, semiColonJoinDefined, setFirst, sh, sleep, spaceJoinDefined, tag, tebibytes, tib, timeZones, tryFallback, tryFallbackAsync, tryJsonParse, ts, typescript, userTimeZone, zsh };
2146
- //# sourceMappingURL=index.js.map
1918
+
1919
+ //# sourceMappingURL=index.js.map