@bitbybit-dev/base 1.3.2-rc.1 → 1.4.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +2 -0
- package/lib/api/inputs/base-inputs.d.ts +10 -4
- package/lib/api/inputs/color-inputs.d.ts +24 -23
- package/lib/api/inputs/color-inputs.js +1 -0
- package/lib/api/inputs/dates-inputs.d.ts +16 -16
- package/lib/api/inputs/frame-inputs.d.ts +515 -0
- package/lib/api/inputs/frame-inputs.js +617 -0
- package/lib/api/inputs/index.d.ts +1 -0
- package/lib/api/inputs/index.js +1 -0
- package/lib/api/inputs/io-inputs.d.ts +3 -3
- package/lib/api/inputs/io-inputs.js +1 -1
- package/lib/api/inputs/lists-inputs.d.ts +23 -23
- package/lib/api/inputs/logic-inputs.d.ts +11 -11
- package/lib/api/inputs/math-inputs.d.ts +49 -49
- package/lib/api/inputs/math-inputs.js +4 -4
- package/lib/api/inputs/mesh-inputs.d.ts +3 -3
- package/lib/api/inputs/mesh-inputs.js +3 -3
- package/lib/api/inputs/point-inputs.d.ts +39 -38
- package/lib/api/inputs/point-inputs.js +6 -5
- package/lib/api/inputs/polyline-inputs.d.ts +5 -4
- package/lib/api/inputs/polyline-inputs.js +3 -3
- package/lib/api/inputs/text-inputs.d.ts +34 -33
- package/lib/api/inputs/text-inputs.js +15 -12
- package/lib/api/inputs/transforms-inputs.d.ts +16 -16
- package/lib/api/inputs/vector-inputs.d.ts +26 -25
- package/lib/api/inputs/vector-inputs.js +2 -1
- package/lib/api/kernel-calls/call-by-path.d.ts +12 -0
- package/lib/api/kernel-calls/call-by-path.js +36 -0
- package/lib/api/kernel-calls/constraints.d.ts +53 -0
- package/lib/api/kernel-calls/constraints.js +21 -0
- package/lib/api/kernel-calls/describe-failure.d.ts +32 -0
- package/lib/api/kernel-calls/describe-failure.js +164 -0
- package/lib/api/kernel-calls/errors.d.ts +55 -0
- package/lib/api/kernel-calls/errors.js +42 -0
- package/lib/api/kernel-calls/failure-message.d.ts +18 -0
- package/lib/api/kernel-calls/failure-message.js +36 -0
- package/lib/api/kernel-calls/index.d.ts +10 -0
- package/lib/api/kernel-calls/index.js +10 -0
- package/lib/api/kernel-calls/input-rules.d.ts +67 -0
- package/lib/api/kernel-calls/input-rules.js +135 -0
- package/lib/api/kernel-calls/input-validation.d.ts +130 -0
- package/lib/api/kernel-calls/input-validation.js +221 -0
- package/lib/api/kernel-calls/rehydrate.d.ts +16 -0
- package/lib/api/kernel-calls/rehydrate.js +38 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +59 -0
- package/lib/api/kernel-calls/resolve-dto.js +61 -0
- package/lib/api/kernel-calls/with-defaults.d.ts +16 -0
- package/lib/api/kernel-calls/with-defaults.js +53 -0
- package/lib/api/resolved-inputs/index.d.ts +304 -0
- package/lib/api/resolved-inputs/index.js +1 -0
- package/lib/api/services/color.js +43 -26
- package/lib/api/services/dates.js +53 -33
- package/lib/api/services/frame.d.ts +670 -0
- package/lib/api/services/frame.js +1040 -0
- package/lib/api/services/helpers/dxf/dxf-generator.d.ts +2 -3
- package/lib/api/services/helpers/dxf/dxf-generator.js +27 -37
- package/lib/api/services/helpers/dxf/dxf.js +10 -4
- package/lib/api/services/helpers/frame-axes.d.ts +36 -0
- package/lib/api/services/helpers/frame-axes.js +57 -0
- package/lib/api/services/helpers/matrices.d.ts +17 -0
- package/lib/api/services/helpers/matrices.js +51 -0
- package/lib/api/services/index.d.ts +1 -0
- package/lib/api/services/index.js +1 -0
- package/lib/api/services/line.js +15 -12
- package/lib/api/services/lists.js +174 -136
- package/lib/api/services/logic.js +44 -34
- package/lib/api/services/math.js +127 -82
- package/lib/api/services/mesh.js +20 -13
- package/lib/api/services/point.js +62 -46
- package/lib/api/services/polyline.js +22 -18
- package/lib/api/services/text.js +81 -46
- package/lib/api/services/transforms.js +38 -25
- package/lib/api/services/vector.js +37 -22
- package/package.json +1 -1
package/lib/api/services/text.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import { defaultsVectorParams } from "../models/simplex";
|
|
3
|
+
import { resolveDto } from "../kernel-calls";
|
|
3
4
|
/**
|
|
4
5
|
* Working with text: splitting, joining, searching, trimming, padding, changing case, regular
|
|
5
6
|
* expressions and formatting with placeholders. `vectorChar` and `vectorText` turn text into line
|
|
@@ -21,7 +22,8 @@ export class TextBitByBit {
|
|
|
21
22
|
* @drawable false
|
|
22
23
|
*/
|
|
23
24
|
create(inputs) {
|
|
24
|
-
|
|
25
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
26
|
+
return resolved.text;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Cuts a text into pieces wherever a separator occurs; the separator itself is dropped.
|
|
@@ -38,7 +40,8 @@ export class TextBitByBit {
|
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
40
42
|
split(inputs) {
|
|
41
|
-
|
|
43
|
+
const resolved = resolveDto(Inputs.Text.TextSplitDto, inputs);
|
|
44
|
+
return resolved.text.split(resolved.separator);
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Replaces every occurrence of a search text with another text.
|
|
@@ -55,7 +58,8 @@ export class TextBitByBit {
|
|
|
55
58
|
* ```
|
|
56
59
|
*/
|
|
57
60
|
replaceAll(inputs) {
|
|
58
|
-
|
|
61
|
+
const resolved = resolveDto(Inputs.Text.TextReplaceDto, inputs);
|
|
62
|
+
return resolved.text.split(resolved.search).join(resolved.replaceWith);
|
|
59
63
|
}
|
|
60
64
|
/**
|
|
61
65
|
* Joins a list of texts into one, with a separator between neighbors.
|
|
@@ -72,7 +76,8 @@ export class TextBitByBit {
|
|
|
72
76
|
* ```
|
|
73
77
|
*/
|
|
74
78
|
join(inputs) {
|
|
75
|
-
|
|
79
|
+
const resolved = resolveDto(Inputs.Text.TextJoinDto, inputs);
|
|
80
|
+
return resolved.list.join(resolved.separator);
|
|
76
81
|
}
|
|
77
82
|
/**
|
|
78
83
|
* Turns any value into text, the way JavaScript prints it.
|
|
@@ -117,8 +122,9 @@ export class TextBitByBit {
|
|
|
117
122
|
* ```
|
|
118
123
|
*/
|
|
119
124
|
format(inputs) {
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
const resolved = resolveDto(Inputs.Text.TextFormatDto, inputs);
|
|
126
|
+
return resolved.text.replace(/{(\d+)}/g, (match, number) => {
|
|
127
|
+
return typeof resolved.values[number] !== "undefined" ? resolved.values[number] : match;
|
|
122
128
|
});
|
|
123
129
|
}
|
|
124
130
|
/**
|
|
@@ -136,7 +142,8 @@ export class TextBitByBit {
|
|
|
136
142
|
* ```
|
|
137
143
|
*/
|
|
138
144
|
includes(inputs) {
|
|
139
|
-
|
|
145
|
+
const resolved = resolveDto(Inputs.Text.TextSearchDto, inputs);
|
|
146
|
+
return resolved.text.includes(resolved.search);
|
|
140
147
|
}
|
|
141
148
|
/**
|
|
142
149
|
* Tells whether a text begins with a search text.
|
|
@@ -153,7 +160,8 @@ export class TextBitByBit {
|
|
|
153
160
|
* ```
|
|
154
161
|
*/
|
|
155
162
|
startsWith(inputs) {
|
|
156
|
-
|
|
163
|
+
const resolved = resolveDto(Inputs.Text.TextSearchDto, inputs);
|
|
164
|
+
return resolved.text.startsWith(resolved.search);
|
|
157
165
|
}
|
|
158
166
|
/**
|
|
159
167
|
* Tells whether a text ends with a search text.
|
|
@@ -170,7 +178,8 @@ export class TextBitByBit {
|
|
|
170
178
|
* ```
|
|
171
179
|
*/
|
|
172
180
|
endsWith(inputs) {
|
|
173
|
-
|
|
181
|
+
const resolved = resolveDto(Inputs.Text.TextSearchDto, inputs);
|
|
182
|
+
return resolved.text.endsWith(resolved.search);
|
|
174
183
|
}
|
|
175
184
|
/**
|
|
176
185
|
* Finds where a search text first occurs, counting characters from 0, or -1 when it does not
|
|
@@ -188,7 +197,8 @@ export class TextBitByBit {
|
|
|
188
197
|
* ```
|
|
189
198
|
*/
|
|
190
199
|
indexOf(inputs) {
|
|
191
|
-
|
|
200
|
+
const resolved = resolveDto(Inputs.Text.TextSearchDto, inputs);
|
|
201
|
+
return resolved.text.indexOf(resolved.search);
|
|
192
202
|
}
|
|
193
203
|
/**
|
|
194
204
|
* Finds where a search text last occurs, counting characters from 0, or -1 when it does not
|
|
@@ -206,7 +216,8 @@ export class TextBitByBit {
|
|
|
206
216
|
* ```
|
|
207
217
|
*/
|
|
208
218
|
lastIndexOf(inputs) {
|
|
209
|
-
|
|
219
|
+
const resolved = resolveDto(Inputs.Text.TextSearchDto, inputs);
|
|
220
|
+
return resolved.text.lastIndexOf(resolved.search);
|
|
210
221
|
}
|
|
211
222
|
/**
|
|
212
223
|
* Takes the characters from a start position up to, but not including, an end position.
|
|
@@ -224,7 +235,8 @@ export class TextBitByBit {
|
|
|
224
235
|
* ```
|
|
225
236
|
*/
|
|
226
237
|
substring(inputs) {
|
|
227
|
-
|
|
238
|
+
const resolved = resolveDto(Inputs.Text.TextSubstringDto, inputs);
|
|
239
|
+
return resolved.text.substring(resolved.start, resolved.end);
|
|
228
240
|
}
|
|
229
241
|
/**
|
|
230
242
|
* Takes the characters from a start position up to, but not including, an end position.
|
|
@@ -242,7 +254,8 @@ export class TextBitByBit {
|
|
|
242
254
|
* ```
|
|
243
255
|
*/
|
|
244
256
|
slice(inputs) {
|
|
245
|
-
|
|
257
|
+
const resolved = resolveDto(Inputs.Text.TextSubstringDto, inputs);
|
|
258
|
+
return resolved.text.slice(resolved.start, resolved.end);
|
|
246
259
|
}
|
|
247
260
|
/**
|
|
248
261
|
* Reads the character at a position, counting from 0.
|
|
@@ -259,7 +272,8 @@ export class TextBitByBit {
|
|
|
259
272
|
* ```
|
|
260
273
|
*/
|
|
261
274
|
charAt(inputs) {
|
|
262
|
-
|
|
275
|
+
const resolved = resolveDto(Inputs.Text.TextIndexDto, inputs);
|
|
276
|
+
return resolved.text.charAt(resolved.index);
|
|
263
277
|
}
|
|
264
278
|
/**
|
|
265
279
|
* Removes spaces, tabs and line breaks from both ends of a text.
|
|
@@ -272,7 +286,8 @@ export class TextBitByBit {
|
|
|
272
286
|
* @drawable false
|
|
273
287
|
*/
|
|
274
288
|
trim(inputs) {
|
|
275
|
-
|
|
289
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
290
|
+
return resolved.text.trim();
|
|
276
291
|
}
|
|
277
292
|
/**
|
|
278
293
|
* Removes spaces, tabs and line breaks from the start of a text.
|
|
@@ -285,7 +300,8 @@ export class TextBitByBit {
|
|
|
285
300
|
* @drawable false
|
|
286
301
|
*/
|
|
287
302
|
trimStart(inputs) {
|
|
288
|
-
|
|
303
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
304
|
+
return resolved.text.trimStart();
|
|
289
305
|
}
|
|
290
306
|
/**
|
|
291
307
|
* Removes spaces, tabs and line breaks from the end of a text.
|
|
@@ -298,7 +314,8 @@ export class TextBitByBit {
|
|
|
298
314
|
* @drawable false
|
|
299
315
|
*/
|
|
300
316
|
trimEnd(inputs) {
|
|
301
|
-
|
|
317
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
318
|
+
return resolved.text.trimEnd();
|
|
302
319
|
}
|
|
303
320
|
/**
|
|
304
321
|
* Adds a filler text in front until the text reaches a length; a text already that long is left
|
|
@@ -316,7 +333,8 @@ export class TextBitByBit {
|
|
|
316
333
|
* ```
|
|
317
334
|
*/
|
|
318
335
|
padStart(inputs) {
|
|
319
|
-
|
|
336
|
+
const resolved = resolveDto(Inputs.Text.TextPadDto, inputs);
|
|
337
|
+
return resolved.text.padStart(resolved.length, resolved.padString);
|
|
320
338
|
}
|
|
321
339
|
/**
|
|
322
340
|
* Adds a filler text behind until the text reaches a length; a text already that long is left
|
|
@@ -334,7 +352,8 @@ export class TextBitByBit {
|
|
|
334
352
|
* ```
|
|
335
353
|
*/
|
|
336
354
|
padEnd(inputs) {
|
|
337
|
-
|
|
355
|
+
const resolved = resolveDto(Inputs.Text.TextPadDto, inputs);
|
|
356
|
+
return resolved.text.padEnd(resolved.length, resolved.padString);
|
|
338
357
|
}
|
|
339
358
|
/**
|
|
340
359
|
* Turns every letter into a capital.
|
|
@@ -347,7 +366,8 @@ export class TextBitByBit {
|
|
|
347
366
|
* @drawable false
|
|
348
367
|
*/
|
|
349
368
|
toUpperCase(inputs) {
|
|
350
|
-
|
|
369
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
370
|
+
return resolved.text.toUpperCase();
|
|
351
371
|
}
|
|
352
372
|
/**
|
|
353
373
|
* Turns every letter into lower case.
|
|
@@ -360,7 +380,8 @@ export class TextBitByBit {
|
|
|
360
380
|
* @drawable false
|
|
361
381
|
*/
|
|
362
382
|
toLowerCase(inputs) {
|
|
363
|
-
|
|
383
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
384
|
+
return resolved.text.toLowerCase();
|
|
364
385
|
}
|
|
365
386
|
/**
|
|
366
387
|
* Turns the first character into a capital and leaves the rest as it is.
|
|
@@ -373,9 +394,10 @@ export class TextBitByBit {
|
|
|
373
394
|
* @drawable false
|
|
374
395
|
*/
|
|
375
396
|
toUpperCaseFirst(inputs) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
397
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
398
|
+
if (!resolved.text)
|
|
399
|
+
return resolved.text;
|
|
400
|
+
return resolved.text.charAt(0).toUpperCase() + resolved.text.slice(1);
|
|
379
401
|
}
|
|
380
402
|
/**
|
|
381
403
|
* Turns the first character into lower case and leaves the rest as it is.
|
|
@@ -388,9 +410,10 @@ export class TextBitByBit {
|
|
|
388
410
|
* @drawable false
|
|
389
411
|
*/
|
|
390
412
|
toLowerCaseFirst(inputs) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
413
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
414
|
+
if (!resolved.text)
|
|
415
|
+
return resolved.text;
|
|
416
|
+
return resolved.text.charAt(0).toLowerCase() + resolved.text.slice(1);
|
|
394
417
|
}
|
|
395
418
|
/**
|
|
396
419
|
* Repeats a text a number of times, end to end.
|
|
@@ -407,7 +430,8 @@ export class TextBitByBit {
|
|
|
407
430
|
* ```
|
|
408
431
|
*/
|
|
409
432
|
repeat(inputs) {
|
|
410
|
-
|
|
433
|
+
const resolved = resolveDto(Inputs.Text.TextRepeatDto, inputs);
|
|
434
|
+
return resolved.text.repeat(resolved.count);
|
|
411
435
|
}
|
|
412
436
|
/**
|
|
413
437
|
* Reverses the order of the characters.
|
|
@@ -420,7 +444,8 @@ export class TextBitByBit {
|
|
|
420
444
|
* @drawable false
|
|
421
445
|
*/
|
|
422
446
|
reverse(inputs) {
|
|
423
|
-
|
|
447
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
448
|
+
return resolved.text.split("").reverse().join("");
|
|
424
449
|
}
|
|
425
450
|
/**
|
|
426
451
|
* Counts the characters in a text.
|
|
@@ -433,7 +458,8 @@ export class TextBitByBit {
|
|
|
433
458
|
* @drawable false
|
|
434
459
|
*/
|
|
435
460
|
length(inputs) {
|
|
436
|
-
|
|
461
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
462
|
+
return resolved.text.length;
|
|
437
463
|
}
|
|
438
464
|
/**
|
|
439
465
|
* Tells whether a text is empty or holds only whitespace.
|
|
@@ -446,7 +472,8 @@ export class TextBitByBit {
|
|
|
446
472
|
* @drawable false
|
|
447
473
|
*/
|
|
448
474
|
isEmpty(inputs) {
|
|
449
|
-
|
|
475
|
+
const resolved = resolveDto(Inputs.Text.TextDto, inputs);
|
|
476
|
+
return !resolved.text || resolved.text.trim().length === 0;
|
|
450
477
|
}
|
|
451
478
|
/**
|
|
452
479
|
* Joins several texts into one with nothing between them.
|
|
@@ -463,7 +490,8 @@ export class TextBitByBit {
|
|
|
463
490
|
* ```
|
|
464
491
|
*/
|
|
465
492
|
concat(inputs) {
|
|
466
|
-
|
|
493
|
+
const resolved = resolveDto(Inputs.Text.TextConcatDto, inputs);
|
|
494
|
+
return resolved.texts.join("");
|
|
467
495
|
}
|
|
468
496
|
/**
|
|
469
497
|
* Tells whether a regular expression matches somewhere in a text.
|
|
@@ -480,8 +508,9 @@ export class TextBitByBit {
|
|
|
480
508
|
* ```
|
|
481
509
|
*/
|
|
482
510
|
regexTest(inputs) {
|
|
483
|
-
const
|
|
484
|
-
|
|
511
|
+
const resolved = resolveDto(Inputs.Text.TextRegexDto, inputs);
|
|
512
|
+
const regex = new RegExp(resolved.pattern, resolved.flags);
|
|
513
|
+
return regex.test(resolved.text);
|
|
485
514
|
}
|
|
486
515
|
/**
|
|
487
516
|
* Finds the parts of a text that a regular expression matches.
|
|
@@ -500,8 +529,9 @@ export class TextBitByBit {
|
|
|
500
529
|
* ```
|
|
501
530
|
*/
|
|
502
531
|
regexMatch(inputs) {
|
|
503
|
-
const
|
|
504
|
-
const
|
|
532
|
+
const resolved = resolveDto(Inputs.Text.TextRegexDto, inputs);
|
|
533
|
+
const regex = new RegExp(resolved.pattern, resolved.flags);
|
|
534
|
+
const result = resolved.text.match(regex);
|
|
505
535
|
return result ? Array.from(result) : null;
|
|
506
536
|
}
|
|
507
537
|
/**
|
|
@@ -520,8 +550,9 @@ export class TextBitByBit {
|
|
|
520
550
|
* ```
|
|
521
551
|
*/
|
|
522
552
|
regexReplace(inputs) {
|
|
523
|
-
const
|
|
524
|
-
|
|
553
|
+
const resolved = resolveDto(Inputs.Text.TextRegexReplaceDto, inputs);
|
|
554
|
+
const regex = new RegExp(resolved.pattern, resolved.flags);
|
|
555
|
+
return resolved.text.replace(regex, resolved.replaceWith);
|
|
525
556
|
}
|
|
526
557
|
/**
|
|
527
558
|
* Finds where a regular expression first matches, counting characters from 0, or -1 when it
|
|
@@ -539,8 +570,9 @@ export class TextBitByBit {
|
|
|
539
570
|
* ```
|
|
540
571
|
*/
|
|
541
572
|
regexSearch(inputs) {
|
|
542
|
-
const
|
|
543
|
-
|
|
573
|
+
const resolved = resolveDto(Inputs.Text.TextRegexDto, inputs);
|
|
574
|
+
const regex = new RegExp(resolved.pattern, resolved.flags);
|
|
575
|
+
return resolved.text.search(regex);
|
|
544
576
|
}
|
|
545
577
|
/**
|
|
546
578
|
* Cuts a text into pieces wherever a regular expression matches; the matches themselves are
|
|
@@ -558,8 +590,9 @@ export class TextBitByBit {
|
|
|
558
590
|
* ```
|
|
559
591
|
*/
|
|
560
592
|
regexSplit(inputs) {
|
|
561
|
-
const
|
|
562
|
-
|
|
593
|
+
const resolved = resolveDto(Inputs.Text.TextRegexDto, inputs);
|
|
594
|
+
const regex = new RegExp(resolved.pattern, resolved.flags);
|
|
595
|
+
return resolved.text.split(regex);
|
|
563
596
|
}
|
|
564
597
|
/**
|
|
565
598
|
* Draws one character as line paths with a simple stroke font.
|
|
@@ -579,7 +612,8 @@ export class TextBitByBit {
|
|
|
579
612
|
* ```
|
|
580
613
|
*/
|
|
581
614
|
vectorChar(inputs) {
|
|
582
|
-
const
|
|
615
|
+
const resolved = resolveDto(Inputs.Text.VectorCharDto, inputs);
|
|
616
|
+
const { xOffset, yOffset, font, input, height, extrudeOffset } = this.vectorParamsChar(resolved);
|
|
583
617
|
let code = input.charCodeAt(0);
|
|
584
618
|
if (!code || !font[code]) {
|
|
585
619
|
code = 63;
|
|
@@ -629,8 +663,9 @@ export class TextBitByBit {
|
|
|
629
663
|
* ```
|
|
630
664
|
*/
|
|
631
665
|
vectorText(inputs) {
|
|
632
|
-
const
|
|
633
|
-
const
|
|
666
|
+
const resolved = resolveDto(Inputs.Text.VectorTextDto, inputs);
|
|
667
|
+
const { xOffset, yOffset, height, align, extrudeOffset, lineSpacing, letterSpacing } = Object.assign({}, defaultsVectorParams, resolved);
|
|
668
|
+
const text = resolved.text;
|
|
634
669
|
if (typeof text !== "string")
|
|
635
670
|
throw new Error("text must be a string");
|
|
636
671
|
const extraLetterSpacing = (height * letterSpacing);
|
|
@@ -678,7 +713,7 @@ export class TextBitByBit {
|
|
|
678
713
|
return line;
|
|
679
714
|
}
|
|
680
715
|
});
|
|
681
|
-
if (
|
|
716
|
+
if (resolved.centerOnOrigin) {
|
|
682
717
|
const pointsFlat = [];
|
|
683
718
|
lines.forEach((line) => {
|
|
684
719
|
line.chars.forEach((vchar) => {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as Inputs from "../inputs";
|
|
2
|
+
import { resolveDto } from "../kernel-calls";
|
|
1
3
|
/**
|
|
2
4
|
* Builds transformation matrices for moving, rotating, scaling and stretching geometry. A
|
|
3
5
|
* transformation is a 4x4 matrix as 16 numbers in column-major order; most methods return a short
|
|
@@ -30,10 +32,11 @@ export class Transforms {
|
|
|
30
32
|
* ```
|
|
31
33
|
*/
|
|
32
34
|
rotationCenterAxis(inputs) {
|
|
35
|
+
const resolved = resolveDto(Inputs.Transforms.RotationCenterAxisDto, inputs);
|
|
33
36
|
return [
|
|
34
|
-
this.translation(-
|
|
35
|
-
this.rotationAxis(
|
|
36
|
-
this.translation(
|
|
37
|
+
this.translation(-resolved.center[0], -resolved.center[1], -resolved.center[2]),
|
|
38
|
+
this.rotationAxis(resolved.axis, this.math.degToRad({ number: resolved.angle })),
|
|
39
|
+
this.translation(resolved.center[0], resolved.center[1], resolved.center[2]),
|
|
37
40
|
];
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
@@ -54,10 +57,11 @@ export class Transforms {
|
|
|
54
57
|
* ```
|
|
55
58
|
*/
|
|
56
59
|
rotationCenterX(inputs) {
|
|
60
|
+
const resolved = resolveDto(Inputs.Transforms.RotationCenterDto, inputs);
|
|
57
61
|
return [
|
|
58
|
-
this.translation(-
|
|
59
|
-
this.rotationX(this.math.degToRad({ number:
|
|
60
|
-
this.translation(
|
|
62
|
+
this.translation(-resolved.center[0], -resolved.center[1], -resolved.center[2]),
|
|
63
|
+
this.rotationX(this.math.degToRad({ number: resolved.angle })),
|
|
64
|
+
this.translation(resolved.center[0], resolved.center[1], resolved.center[2]),
|
|
61
65
|
];
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
@@ -78,10 +82,11 @@ export class Transforms {
|
|
|
78
82
|
* ```
|
|
79
83
|
*/
|
|
80
84
|
rotationCenterY(inputs) {
|
|
85
|
+
const resolved = resolveDto(Inputs.Transforms.RotationCenterDto, inputs);
|
|
81
86
|
return [
|
|
82
|
-
this.translation(-
|
|
83
|
-
this.rotationY(this.math.degToRad({ number:
|
|
84
|
-
this.translation(
|
|
87
|
+
this.translation(-resolved.center[0], -resolved.center[1], -resolved.center[2]),
|
|
88
|
+
this.rotationY(this.math.degToRad({ number: resolved.angle })),
|
|
89
|
+
this.translation(resolved.center[0], resolved.center[1], resolved.center[2]),
|
|
85
90
|
];
|
|
86
91
|
}
|
|
87
92
|
/**
|
|
@@ -102,10 +107,11 @@ export class Transforms {
|
|
|
102
107
|
* ```
|
|
103
108
|
*/
|
|
104
109
|
rotationCenterZ(inputs) {
|
|
110
|
+
const resolved = resolveDto(Inputs.Transforms.RotationCenterDto, inputs);
|
|
105
111
|
return [
|
|
106
|
-
this.translation(-
|
|
107
|
-
this.rotationZ(this.math.degToRad({ number:
|
|
108
|
-
this.translation(
|
|
112
|
+
this.translation(-resolved.center[0], -resolved.center[1], -resolved.center[2]),
|
|
113
|
+
this.rotationZ(this.math.degToRad({ number: resolved.angle })),
|
|
114
|
+
this.translation(resolved.center[0], resolved.center[1], resolved.center[2]),
|
|
109
115
|
];
|
|
110
116
|
}
|
|
111
117
|
/**
|
|
@@ -126,10 +132,11 @@ export class Transforms {
|
|
|
126
132
|
* ```
|
|
127
133
|
*/
|
|
128
134
|
rotationCenterYawPitchRoll(inputs) {
|
|
135
|
+
const resolved = resolveDto(Inputs.Transforms.RotationCenterYawPitchRollDto, inputs);
|
|
129
136
|
return [
|
|
130
|
-
this.translation(-
|
|
131
|
-
this.rotationYawPitchRoll(this.math.degToRad({ number:
|
|
132
|
-
this.translation(
|
|
137
|
+
this.translation(-resolved.center[0], -resolved.center[1], -resolved.center[2]),
|
|
138
|
+
this.rotationYawPitchRoll(this.math.degToRad({ number: resolved.yaw }), this.math.degToRad({ number: resolved.pitch }), this.math.degToRad({ number: resolved.roll })),
|
|
139
|
+
this.translation(resolved.center[0], resolved.center[1], resolved.center[2]),
|
|
133
140
|
];
|
|
134
141
|
}
|
|
135
142
|
/**
|
|
@@ -150,10 +157,11 @@ export class Transforms {
|
|
|
150
157
|
* ```
|
|
151
158
|
*/
|
|
152
159
|
scaleCenterXYZ(inputs) {
|
|
160
|
+
const resolved = resolveDto(Inputs.Transforms.ScaleCenterXYZDto, inputs);
|
|
153
161
|
return [
|
|
154
|
-
this.translation(-
|
|
155
|
-
this.scaling(
|
|
156
|
-
this.translation(
|
|
162
|
+
this.translation(-resolved.center[0], -resolved.center[1], -resolved.center[2]),
|
|
163
|
+
this.scaling(resolved.scaleXyz[0], resolved.scaleXyz[1], resolved.scaleXyz[2]),
|
|
164
|
+
this.translation(resolved.center[0], resolved.center[1], resolved.center[2]),
|
|
157
165
|
];
|
|
158
166
|
}
|
|
159
167
|
/**
|
|
@@ -171,7 +179,8 @@ export class Transforms {
|
|
|
171
179
|
* ```
|
|
172
180
|
*/
|
|
173
181
|
scaleXYZ(inputs) {
|
|
174
|
-
|
|
182
|
+
const resolved = resolveDto(Inputs.Transforms.ScaleXYZDto, inputs);
|
|
183
|
+
return [this.scaling(resolved.scaleXyz[0], resolved.scaleXyz[1], resolved.scaleXyz[2])];
|
|
175
184
|
}
|
|
176
185
|
/**
|
|
177
186
|
* Builds a stretch along one direction, measured from a center point; distances across that
|
|
@@ -192,7 +201,8 @@ export class Transforms {
|
|
|
192
201
|
* ```
|
|
193
202
|
*/
|
|
194
203
|
stretchDirFromCenter(inputs) {
|
|
195
|
-
const
|
|
204
|
+
const resolved = resolveDto(Inputs.Transforms.StretchDirCenterDto, inputs);
|
|
205
|
+
const { center, direction, scale } = resolved;
|
|
196
206
|
return [
|
|
197
207
|
this.translation(-center[0], -center[1], -center[2]),
|
|
198
208
|
this.stretchDirection(direction, scale),
|
|
@@ -214,7 +224,8 @@ export class Transforms {
|
|
|
214
224
|
* ```
|
|
215
225
|
*/
|
|
216
226
|
uniformScale(inputs) {
|
|
217
|
-
|
|
227
|
+
const resolved = resolveDto(Inputs.Transforms.UniformScaleDto, inputs);
|
|
228
|
+
return [this.scaling(resolved.scale, resolved.scale, resolved.scale)];
|
|
218
229
|
}
|
|
219
230
|
/**
|
|
220
231
|
* Builds a scale by the same factor on every axis, measured from a center point that stays in
|
|
@@ -234,10 +245,11 @@ export class Transforms {
|
|
|
234
245
|
* ```
|
|
235
246
|
*/
|
|
236
247
|
uniformScaleFromCenter(inputs) {
|
|
248
|
+
const resolved = resolveDto(Inputs.Transforms.UniformScaleFromCenterDto, inputs);
|
|
237
249
|
return [
|
|
238
|
-
this.translation(-
|
|
239
|
-
this.scaling(
|
|
240
|
-
this.translation(
|
|
250
|
+
this.translation(-resolved.center[0], -resolved.center[1], -resolved.center[2]),
|
|
251
|
+
this.scaling(resolved.scale, resolved.scale, resolved.scale),
|
|
252
|
+
this.translation(resolved.center[0], resolved.center[1], resolved.center[2]),
|
|
241
253
|
];
|
|
242
254
|
}
|
|
243
255
|
/**
|
|
@@ -255,7 +267,8 @@ export class Transforms {
|
|
|
255
267
|
* ```
|
|
256
268
|
*/
|
|
257
269
|
translationXYZ(inputs) {
|
|
258
|
-
|
|
270
|
+
const resolved = resolveDto(Inputs.Transforms.TranslationXYZDto, inputs);
|
|
271
|
+
return [this.translation(resolved.translation[0], resolved.translation[1], resolved.translation[2])];
|
|
259
272
|
}
|
|
260
273
|
/**
|
|
261
274
|
* Builds one move per vector, for transforming many points each by its own vector.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as Inputs from "../inputs";
|
|
2
|
+
import { resolveDto } from "../kernel-calls";
|
|
1
3
|
/**
|
|
2
4
|
* Vector maths on plain number arrays. A vector is an array of numbers; in 3D it is `[x, y, z]`
|
|
3
5
|
* with Y pointing up, the same shape as a point, so the two can be passed to each other's methods.
|
|
@@ -27,7 +29,8 @@ export class Vector {
|
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
31
|
removeAllDuplicateVectors(inputs) {
|
|
30
|
-
|
|
32
|
+
const resolved = resolveDto(Inputs.Vector.RemoveAllDuplicateVectorsDto, inputs);
|
|
33
|
+
return this.geometryHelper.removeAllDuplicateVectors(resolved.vectors, resolved.tolerance);
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* Removes a vector when it repeats the one right before it; the same vector further away is
|
|
@@ -51,7 +54,8 @@ export class Vector {
|
|
|
51
54
|
* ```
|
|
52
55
|
*/
|
|
53
56
|
removeConsecutiveDuplicateVectors(inputs) {
|
|
54
|
-
|
|
57
|
+
const resolved = resolveDto(Inputs.Vector.RemoveConsecutiveDuplicateVectorsDto, inputs);
|
|
58
|
+
return this.geometryHelper.removeConsecutiveVectorDuplicates(resolved.vectors, resolved.checkFirstAndLast, resolved.tolerance);
|
|
55
59
|
}
|
|
56
60
|
/**
|
|
57
61
|
* Tells whether two vectors are the same within a tolerance, entry by entry.
|
|
@@ -69,7 +73,8 @@ export class Vector {
|
|
|
69
73
|
* ```
|
|
70
74
|
*/
|
|
71
75
|
vectorsTheSame(inputs) {
|
|
72
|
-
|
|
76
|
+
const resolved = resolveDto(Inputs.Vector.VectorsTheSameDto, inputs);
|
|
77
|
+
return this.geometryHelper.vectorsTheSame(resolved.vec1, resolved.vec2, resolved.tolerance);
|
|
73
78
|
}
|
|
74
79
|
/**
|
|
75
80
|
* Measures the angle between two vectors in degrees, always between 0 and 180.
|
|
@@ -274,9 +279,10 @@ export class Vector {
|
|
|
274
279
|
* ```
|
|
275
280
|
*/
|
|
276
281
|
div(inputs) {
|
|
282
|
+
const resolved = resolveDto(Inputs.Vector.VectorScalarDto, inputs);
|
|
277
283
|
const res = [];
|
|
278
|
-
for (let i = 0; i <
|
|
279
|
-
res.push(
|
|
284
|
+
for (let i = 0; i < resolved.vector.length; i++) {
|
|
285
|
+
res.push(resolved.vector[i] / resolved.scalar);
|
|
280
286
|
}
|
|
281
287
|
return res;
|
|
282
288
|
}
|
|
@@ -370,9 +376,10 @@ export class Vector {
|
|
|
370
376
|
* ```
|
|
371
377
|
*/
|
|
372
378
|
lerp(inputs) {
|
|
379
|
+
const resolved = resolveDto(Inputs.Vector.FractionTwoVectorsDto, inputs);
|
|
373
380
|
return this.add({
|
|
374
|
-
first: this.mul({ vector:
|
|
375
|
-
second: this.mul({ vector:
|
|
381
|
+
first: this.mul({ vector: resolved.first, scalar: resolved.fraction }),
|
|
382
|
+
second: this.mul({ vector: resolved.second, scalar: 1.0 - resolved.fraction })
|
|
376
383
|
});
|
|
377
384
|
}
|
|
378
385
|
/**
|
|
@@ -424,9 +431,10 @@ export class Vector {
|
|
|
424
431
|
* ```
|
|
425
432
|
*/
|
|
426
433
|
mul(inputs) {
|
|
434
|
+
const resolved = resolveDto(Inputs.Vector.VectorScalarDto, inputs);
|
|
427
435
|
const res = [];
|
|
428
|
-
for (let i = 0; i <
|
|
429
|
-
res.push(
|
|
436
|
+
for (let i = 0; i < resolved.vector.length; i++) {
|
|
437
|
+
res.push(resolved.vector[i] * resolved.scalar);
|
|
430
438
|
}
|
|
431
439
|
return res;
|
|
432
440
|
}
|
|
@@ -525,7 +533,8 @@ export class Vector {
|
|
|
525
533
|
* ```
|
|
526
534
|
*/
|
|
527
535
|
onRay(inputs) {
|
|
528
|
-
|
|
536
|
+
const resolved = resolveDto(Inputs.Vector.RayPointDto, inputs);
|
|
537
|
+
return this.add({ first: resolved.point, second: this.mul({ vector: resolved.vector, scalar: resolved.distance }) });
|
|
529
538
|
}
|
|
530
539
|
/**
|
|
531
540
|
* Builds a 3D vector from its x, y and z values.
|
|
@@ -542,7 +551,8 @@ export class Vector {
|
|
|
542
551
|
* ```
|
|
543
552
|
*/
|
|
544
553
|
vectorXYZ(inputs) {
|
|
545
|
-
|
|
554
|
+
const resolved = resolveDto(Inputs.Vector.VectorXYZDto, inputs);
|
|
555
|
+
return [resolved.x, resolved.y, resolved.z];
|
|
546
556
|
}
|
|
547
557
|
/**
|
|
548
558
|
* Builds a 2D vector from its x and y values.
|
|
@@ -559,7 +569,8 @@ export class Vector {
|
|
|
559
569
|
* ```
|
|
560
570
|
*/
|
|
561
571
|
vectorXY(inputs) {
|
|
562
|
-
|
|
572
|
+
const resolved = resolveDto(Inputs.Vector.VectorXYDto, inputs);
|
|
573
|
+
return [resolved.x, resolved.y];
|
|
563
574
|
}
|
|
564
575
|
/**
|
|
565
576
|
* Lists the whole numbers from 0 up to, but not including, `max`.
|
|
@@ -576,8 +587,9 @@ export class Vector {
|
|
|
576
587
|
* ```
|
|
577
588
|
*/
|
|
578
589
|
range(inputs) {
|
|
590
|
+
const resolved = resolveDto(Inputs.Vector.RangeMaxDto, inputs);
|
|
579
591
|
const res = [];
|
|
580
|
-
for (let i = 0; i <
|
|
592
|
+
for (let i = 0; i < resolved.max; i++) {
|
|
581
593
|
res.push(i);
|
|
582
594
|
}
|
|
583
595
|
return res;
|
|
@@ -628,8 +640,9 @@ export class Vector {
|
|
|
628
640
|
* ```
|
|
629
641
|
*/
|
|
630
642
|
span(inputs) {
|
|
643
|
+
const resolved = resolveDto(Inputs.Vector.SpanDto, inputs);
|
|
631
644
|
const res = [];
|
|
632
|
-
for (let i =
|
|
645
|
+
for (let i = resolved.min; i <= resolved.max; i += resolved.step) {
|
|
633
646
|
res.push(i);
|
|
634
647
|
}
|
|
635
648
|
return res;
|
|
@@ -652,12 +665,13 @@ export class Vector {
|
|
|
652
665
|
* ```
|
|
653
666
|
*/
|
|
654
667
|
spanEaseItems(inputs) {
|
|
668
|
+
const resolved = resolveDto(Inputs.Vector.SpanEaseItemsDto, inputs);
|
|
655
669
|
const res = [];
|
|
656
|
-
for (let i = 0; i <
|
|
657
|
-
const x = i * 1 / (
|
|
658
|
-
res.push(this.math.ease({ x: x, ease:
|
|
670
|
+
for (let i = 0; i < resolved.nrItems; i++) {
|
|
671
|
+
const x = i * 1 / (resolved.nrItems - 1);
|
|
672
|
+
res.push(this.math.ease({ x: x, ease: resolved.ease, min: resolved.min, max: resolved.max }));
|
|
659
673
|
}
|
|
660
|
-
if (
|
|
674
|
+
if (resolved.intervals) {
|
|
661
675
|
return res.map((v, i, a) => i === 0 ? v : v - a[i - 1]);
|
|
662
676
|
}
|
|
663
677
|
return res;
|
|
@@ -677,11 +691,12 @@ export class Vector {
|
|
|
677
691
|
* ```
|
|
678
692
|
*/
|
|
679
693
|
spanLinearItems(inputs) {
|
|
694
|
+
const resolved = resolveDto(Inputs.Vector.SpanLinearItemsDto, inputs);
|
|
680
695
|
const res = [];
|
|
681
|
-
const dist = (
|
|
682
|
-
for (let i = 0; i <
|
|
683
|
-
const x = dist * i / (
|
|
684
|
-
res.push(x +
|
|
696
|
+
const dist = (resolved.max - resolved.min);
|
|
697
|
+
for (let i = 0; i < resolved.nrItems; i++) {
|
|
698
|
+
const x = dist * i / (resolved.nrItems - 1);
|
|
699
|
+
res.push(x + resolved.min);
|
|
685
700
|
}
|
|
686
701
|
return res;
|
|
687
702
|
}
|