@bitbybit-dev/base 1.2.0 → 1.3.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.
Files changed (55) hide show
  1. package/lib/api/GlobalCDNProvider.js +1 -1
  2. package/lib/api/inputs/base-inputs.d.ts +13 -12
  3. package/lib/api/inputs/color-inputs.d.ts +97 -48
  4. package/lib/api/inputs/color-inputs.js +95 -46
  5. package/lib/api/inputs/dates-inputs.d.ts +67 -26
  6. package/lib/api/inputs/dates-inputs.js +57 -16
  7. package/lib/api/inputs/io-inputs.d.ts +13 -15
  8. package/lib/api/inputs/io-inputs.js +7 -8
  9. package/lib/api/inputs/line-inputs.d.ts +88 -33
  10. package/lib/api/inputs/line-inputs.js +61 -11
  11. package/lib/api/inputs/lists-inputs.d.ts +207 -96
  12. package/lib/api/inputs/lists-inputs.js +153 -45
  13. package/lib/api/inputs/logic-inputs.d.ts +52 -22
  14. package/lib/api/inputs/logic-inputs.js +41 -12
  15. package/lib/api/inputs/math-inputs.d.ts +113 -52
  16. package/lib/api/inputs/math-inputs.js +112 -51
  17. package/lib/api/inputs/mesh-inputs.d.ts +30 -11
  18. package/lib/api/inputs/mesh-inputs.js +21 -3
  19. package/lib/api/inputs/point-inputs.d.ts +240 -107
  20. package/lib/api/inputs/point-inputs.js +199 -73
  21. package/lib/api/inputs/polyline-inputs.d.ts +68 -28
  22. package/lib/api/inputs/polyline-inputs.js +48 -13
  23. package/lib/api/inputs/text-inputs.d.ts +117 -46
  24. package/lib/api/inputs/text-inputs.js +111 -41
  25. package/lib/api/inputs/transforms-inputs.d.ts +65 -23
  26. package/lib/api/inputs/transforms-inputs.js +64 -22
  27. package/lib/api/inputs/vector-inputs.d.ts +154 -76
  28. package/lib/api/inputs/vector-inputs.js +132 -57
  29. package/lib/api/models/point/hex-grid-data.d.ts +1 -1
  30. package/lib/api/models/point/hex-grid-data.js +1 -1
  31. package/lib/api/services/color.d.ts +149 -70
  32. package/lib/api/services/color.js +149 -70
  33. package/lib/api/services/dates.d.ts +313 -150
  34. package/lib/api/services/dates.js +313 -150
  35. package/lib/api/services/line.d.ts +138 -68
  36. package/lib/api/services/line.js +138 -68
  37. package/lib/api/services/lists.d.ts +357 -177
  38. package/lib/api/services/lists.js +357 -177
  39. package/lib/api/services/logic.d.ts +98 -45
  40. package/lib/api/services/logic.js +98 -45
  41. package/lib/api/services/math.d.ts +363 -211
  42. package/lib/api/services/math.js +363 -211
  43. package/lib/api/services/mesh.d.ts +73 -31
  44. package/lib/api/services/mesh.js +73 -31
  45. package/lib/api/services/point.d.ts +367 -147
  46. package/lib/api/services/point.js +367 -147
  47. package/lib/api/services/polyline.d.ts +146 -71
  48. package/lib/api/services/polyline.js +146 -71
  49. package/lib/api/services/text.d.ts +320 -165
  50. package/lib/api/services/text.js +320 -165
  51. package/lib/api/services/transforms.d.ts +145 -58
  52. package/lib/api/services/transforms.js +145 -58
  53. package/lib/api/services/vector.d.ts +381 -156
  54. package/lib/api/services/vector.js +381 -156
  55. package/package.json +1 -1
@@ -1,110 +1,163 @@
1
1
  import * as Inputs from "../inputs";
2
2
  /**
3
- * Contains various logic methods.
3
+ * Booleans and decisions: comparing values, flipping booleans, turning lists of numbers into lists
4
+ * of booleans by thresholds, drawing random booleans, and gating a value so it passes only when a
5
+ * condition holds. The threshold methods are the usual way to decide which items of a pattern get a
6
+ * feature and which do not.
4
7
  */
5
8
  export declare class Logic {
6
9
  /**
7
- * Creates and returns a boolean value (pass-through for boolean input).
8
- * Example: true → true, false → false
9
- * @param inputs a true or false boolean
10
- * @returns boolean
10
+ * Passes a boolean through unchanged, so a value can be given a name and reused.
11
+ *
12
+ * Example: true -> true
13
+ * @param inputs - The boolean
14
+ * @returns The same boolean
11
15
  * @group create
12
16
  * @shortname boolean
13
17
  * @drawable false
14
18
  */
15
19
  boolean(inputs: Inputs.Logic.BooleanDto): boolean;
16
20
  /**
17
- * Generates a random boolean list where each value has a threshold chance of being true.
18
- * Example: length=5, threshold=0.7 → might produce [true, true, false, true, true]
19
- * @param inputs a length and a threshold for randomization of true values
20
- * @returns booleans
21
+ * Draws a list of random booleans, each true with a given probability.
22
+ *
23
+ * Example: length 5 with trueThreshold 0.7 -> perhaps [true, true, false, true, true]
24
+ * @param inputs - How many booleans to draw and the probability of true
25
+ * @returns The random booleans
21
26
  * @group create
22
27
  * @shortname random booleans
23
28
  * @drawable false
29
+ * @example
30
+ * ```typescript
31
+ * const flags = bitbybit.logic.randomBooleans({ length: 5, trueThreshold: 0.7 });
32
+ * ```
24
33
  */
25
34
  randomBooleans(inputs: Inputs.Logic.RandomBooleansDto): boolean[];
26
35
  /**
27
- * Converts numbers to booleans using two thresholds with gradient randomization between them.
28
- * Values below trueThreshold → always true, above falseThreshold → always false.
29
- * Between thresholds → probability gradient (closer to false threshold = higher chance of false).
30
- * Example: [0.1, 0.4, 0.6, 0.9] with thresholds [0.3, 0.7] → [true, gradient, gradient, false]
31
- * @param inputs a length and a threshold for randomization of true values
32
- * @returns booleans
36
+ * Turns numbers into booleans with a random blend between two thresholds.
37
+ *
38
+ * Below the first threshold a number is always true, above the second always false; in between,
39
+ * the chance of true falls in steps from one to the other, so a pattern fades out instead of
40
+ * switching sharply.
41
+ * Example: [0.1, 0.9] with thresholds 0.3 and 0.7 -> [true, false]
42
+ * @param inputs - The numbers, the two thresholds and how many steps the fade has
43
+ * @returns One boolean per number
33
44
  * @group create
34
45
  * @shortname 2 threshold random gradient
35
46
  * @drawable false
47
+ * @example
48
+ * ```typescript
49
+ * const fade = bitbybit.logic.twoThresholdRandomGradient({
50
+ * numbers: [0.1, 0.4, 0.6, 0.9],
51
+ * thresholdTotalTrue: 0.3,
52
+ * thresholdTotalFalse: 0.7,
53
+ * nrLevels: 10,
54
+ * });
55
+ * ```
36
56
  */
37
57
  twoThresholdRandomGradient(inputs: Inputs.Logic.TwoThresholdRandomGradientDto): boolean[];
38
58
  /**
39
- * Converts numbers to booleans based on a threshold (below threshold → true, above → false).
40
- * Can be inverted to flip the logic.
41
- * Example: [0.3, 0.7, 0.5] with threshold=0.6 → [true, false, true]
42
- * @param inputs a length and a threshold for randomization of true values
43
- * @returns booleans
59
+ * Turns numbers into booleans: true below the threshold, false at or above it.
60
+ *
61
+ * `inverse` flips every result.
62
+ * Example: [0.3, 0.7, 0.5] with threshold 0.6 -> [true, false, true]
63
+ * @param inputs - The numbers, the threshold and whether to flip the result
64
+ * @returns One boolean per number
44
65
  * @group create
45
66
  * @shortname threshold boolean list
46
67
  * @drawable false
68
+ * @example
69
+ * ```typescript
70
+ * const below = bitbybit.logic.thresholdBooleanList({ numbers: [0.3, 0.7, 0.5], threshold: 0.6, inverse: false });
71
+ * ```
47
72
  */
48
73
  thresholdBooleanList(inputs: Inputs.Logic.ThresholdBooleanListDto): boolean[];
49
74
  /**
50
- * Converts numbers to booleans using multiple range thresholds (gaps define true ranges).
51
- * Values within any gap range → true, outside all gaps → false. Can be inverted.
52
- * Example: [0.2, 0.5, 0.8] with gaps [[0.3, 0.6], [0.7, 0.9]] → [false, true, true]
53
- * @param inputs a length and a threshold for randomization of true values
54
- * @returns booleans
75
+ * Turns numbers into booleans: true when the number falls inside any of the given ranges, false
76
+ * otherwise.
77
+ *
78
+ * Each range is `[min, max]` with both ends included; `inverse` flips every result.
79
+ * Example: [0.2, 0.5, 0.8] with ranges [[0.3, 0.6], [0.7, 0.9]] -> [false, true, true]
80
+ * @param inputs - The numbers, the ranges and whether to flip the result
81
+ * @returns One boolean per number
55
82
  * @group create
56
83
  * @shortname threshold gaps boolean list
57
84
  * @drawable false
85
+ * @example
86
+ * ```typescript
87
+ * const inside = bitbybit.logic.thresholdGapsBooleanList({
88
+ * numbers: [0.2, 0.5, 0.8],
89
+ * gapThresholds: [[0.3, 0.6], [0.7, 0.9]],
90
+ * inverse: false,
91
+ * });
92
+ * ```
58
93
  */
59
94
  thresholdGapsBooleanList(inputs: Inputs.Logic.ThresholdGapsBooleanListDto): boolean[];
60
95
  /**
61
- * Applies NOT operator to flip a boolean value.
62
- * Example: true → false, false → true
63
- * @param inputs a true or false boolean
64
- * @returns boolean
96
+ * Flips a boolean: true becomes false and false becomes true.
97
+ *
98
+ * Example: true -> false
99
+ * @param inputs - The boolean
100
+ * @returns The opposite boolean
65
101
  * @group edit
66
102
  * @shortname not
67
103
  * @drawable false
68
104
  */
69
105
  not(inputs: Inputs.Logic.BooleanDto): boolean;
70
106
  /**
71
- * Applies NOT operator to flip all boolean values in a list.
72
- * Example: [true, false, true] → [false, true, false]
73
- * @param inputs a list of true or false booleans
74
- * @returns booleans
107
+ * Flips every boolean in a list.
108
+ *
109
+ * Example: [true, false, true] -> [false, true, false]
110
+ * @param inputs - The booleans
111
+ * @returns The flipped booleans, in the same order
75
112
  * @group edit
76
113
  * @shortname not list
77
114
  * @drawable false
78
115
  */
79
116
  notList(inputs: Inputs.Logic.BooleanListDto): boolean[];
80
117
  /**
81
- * Compares two values using various operators (==, !=, ===, !==, <, <=, >, >=).
82
- * Example: 5 > 3 → true, 'hello' === 'world' → false
83
- * @param inputs two values to be compared
84
- * @returns Result of the comparison
118
+ * Compares two values with an operator: less, less or equal, greater, greater or equal, equal
119
+ * or not equal, in the loose (`==`) or strict (`===`) form.
120
+ *
121
+ * Example: 5 greater than 3 -> true; 'hello' strictly equal to 'world' -> false
122
+ * @param inputs - The two values and the operator
123
+ * @returns The result of the comparison
85
124
  * @group operations
86
125
  * @shortname compare
87
126
  * @drawable false
127
+ * @example
128
+ * ```typescript
129
+ * const bigger = bitbybit.logic.compare({ first: 5, second: 3, operator: Bit.Inputs.Logic.BooleanOperatorsEnum.greater });
130
+ * ```
88
131
  */
89
132
  compare<T>(inputs: Inputs.Logic.ComparisonDto<T>): boolean;
90
133
  /**
91
- * Conditionally passes a value through if boolean is true, otherwise returns undefined.
92
- * Example: value=42, boolean=true → 42, value=42, boolean=false → undefined
93
- * @param inputs a value and a boolean value
94
- * @returns value or undefined
134
+ * Lets a value through when the boolean is true and gives undefined when it is false.
135
+ *
136
+ * Example: 42 with true -> 42; 42 with false -> undefined
137
+ * @param inputs - The value and the boolean that opens the gate
138
+ * @returns The value, or undefined when the gate is closed
95
139
  * @group operations
96
140
  * @shortname value gate
97
141
  * @drawable false
142
+ * @example
143
+ * ```typescript
144
+ * const maybe = bitbybit.logic.valueGate({ value: 42, boolean: true });
145
+ * ```
98
146
  */
99
147
  valueGate<T>(inputs: Inputs.Logic.ValueGateDto<T>): T | undefined;
100
148
  /**
101
- * Returns the first defined (non-undefined) value from two options (fallback pattern).
102
- * Example: value1=42, value2=10 → 42, value1=undefined, value2=10 → 10
103
- * @param inputs two values
104
- * @returns value or undefined
149
+ * Picks the first of two values that is defined, so the second acts as a fallback.
150
+ *
151
+ * Example: 42 and 10 -> 42; undefined and 10 -> 10
152
+ * @param inputs - The preferred value and the fallback
153
+ * @returns The first defined value, or undefined when both are missing
105
154
  * @group operations
106
155
  * @shortname first defined value gate
107
156
  * @drawable false
157
+ * @example
158
+ * ```typescript
159
+ * const chosen = bitbybit.logic.firstDefinedValueGate({ value1: undefined, value2: 10 });
160
+ * ```
108
161
  */
109
162
  firstDefinedValueGate<T, U>(inputs: Inputs.Logic.TwoValueGateDto<T, U>): T | U | undefined;
110
163
  }
@@ -1,12 +1,16 @@
1
1
  /**
2
- * Contains various logic methods.
2
+ * Booleans and decisions: comparing values, flipping booleans, turning lists of numbers into lists
3
+ * of booleans by thresholds, drawing random booleans, and gating a value so it passes only when a
4
+ * condition holds. The threshold methods are the usual way to decide which items of a pattern get a
5
+ * feature and which do not.
3
6
  */
4
7
  export class Logic {
5
8
  /**
6
- * Creates and returns a boolean value (pass-through for boolean input).
7
- * Example: true → true, false → false
8
- * @param inputs a true or false boolean
9
- * @returns boolean
9
+ * Passes a boolean through unchanged, so a value can be given a name and reused.
10
+ *
11
+ * Example: true -> true
12
+ * @param inputs - The boolean
13
+ * @returns The same boolean
10
14
  * @group create
11
15
  * @shortname boolean
12
16
  * @drawable false
@@ -15,13 +19,18 @@ export class Logic {
15
19
  return inputs.boolean;
16
20
  }
17
21
  /**
18
- * Generates a random boolean list where each value has a threshold chance of being true.
19
- * Example: length=5, threshold=0.7 → might produce [true, true, false, true, true]
20
- * @param inputs a length and a threshold for randomization of true values
21
- * @returns booleans
22
+ * Draws a list of random booleans, each true with a given probability.
23
+ *
24
+ * Example: length 5 with trueThreshold 0.7 -> perhaps [true, true, false, true, true]
25
+ * @param inputs - How many booleans to draw and the probability of true
26
+ * @returns The random booleans
22
27
  * @group create
23
28
  * @shortname random booleans
24
29
  * @drawable false
30
+ * @example
31
+ * ```typescript
32
+ * const flags = bitbybit.logic.randomBooleans({ length: 5, trueThreshold: 0.7 });
33
+ * ```
25
34
  */
26
35
  randomBooleans(inputs) {
27
36
  const booleans = [];
@@ -31,15 +40,26 @@ export class Logic {
31
40
  return booleans;
32
41
  }
33
42
  /**
34
- * Converts numbers to booleans using two thresholds with gradient randomization between them.
35
- * Values below trueThreshold → always true, above falseThreshold → always false.
36
- * Between thresholds → probability gradient (closer to false threshold = higher chance of false).
37
- * Example: [0.1, 0.4, 0.6, 0.9] with thresholds [0.3, 0.7] → [true, gradient, gradient, false]
38
- * @param inputs a length and a threshold for randomization of true values
39
- * @returns booleans
43
+ * Turns numbers into booleans with a random blend between two thresholds.
44
+ *
45
+ * Below the first threshold a number is always true, above the second always false; in between,
46
+ * the chance of true falls in steps from one to the other, so a pattern fades out instead of
47
+ * switching sharply.
48
+ * Example: [0.1, 0.9] with thresholds 0.3 and 0.7 -> [true, false]
49
+ * @param inputs - The numbers, the two thresholds and how many steps the fade has
50
+ * @returns One boolean per number
40
51
  * @group create
41
52
  * @shortname 2 threshold random gradient
42
53
  * @drawable false
54
+ * @example
55
+ * ```typescript
56
+ * const fade = bitbybit.logic.twoThresholdRandomGradient({
57
+ * numbers: [0.1, 0.4, 0.6, 0.9],
58
+ * thresholdTotalTrue: 0.3,
59
+ * thresholdTotalFalse: 0.7,
60
+ * nrLevels: 10,
61
+ * });
62
+ * ```
43
63
  */
44
64
  twoThresholdRandomGradient(inputs) {
45
65
  const booleans = [];
@@ -67,14 +87,19 @@ export class Logic {
67
87
  return booleans;
68
88
  }
69
89
  /**
70
- * Converts numbers to booleans based on a threshold (below threshold → true, above → false).
71
- * Can be inverted to flip the logic.
72
- * Example: [0.3, 0.7, 0.5] with threshold=0.6 → [true, false, true]
73
- * @param inputs a length and a threshold for randomization of true values
74
- * @returns booleans
90
+ * Turns numbers into booleans: true below the threshold, false at or above it.
91
+ *
92
+ * `inverse` flips every result.
93
+ * Example: [0.3, 0.7, 0.5] with threshold 0.6 -> [true, false, true]
94
+ * @param inputs - The numbers, the threshold and whether to flip the result
95
+ * @returns One boolean per number
75
96
  * @group create
76
97
  * @shortname threshold boolean list
77
98
  * @drawable false
99
+ * @example
100
+ * ```typescript
101
+ * const below = bitbybit.logic.thresholdBooleanList({ numbers: [0.3, 0.7, 0.5], threshold: 0.6, inverse: false });
102
+ * ```
78
103
  */
79
104
  thresholdBooleanList(inputs) {
80
105
  const booleans = [];
@@ -92,14 +117,24 @@ export class Logic {
92
117
  return booleans;
93
118
  }
94
119
  /**
95
- * Converts numbers to booleans using multiple range thresholds (gaps define true ranges).
96
- * Values within any gap range → true, outside all gaps → false. Can be inverted.
97
- * Example: [0.2, 0.5, 0.8] with gaps [[0.3, 0.6], [0.7, 0.9]] → [false, true, true]
98
- * @param inputs a length and a threshold for randomization of true values
99
- * @returns booleans
120
+ * Turns numbers into booleans: true when the number falls inside any of the given ranges, false
121
+ * otherwise.
122
+ *
123
+ * Each range is `[min, max]` with both ends included; `inverse` flips every result.
124
+ * Example: [0.2, 0.5, 0.8] with ranges [[0.3, 0.6], [0.7, 0.9]] -> [false, true, true]
125
+ * @param inputs - The numbers, the ranges and whether to flip the result
126
+ * @returns One boolean per number
100
127
  * @group create
101
128
  * @shortname threshold gaps boolean list
102
129
  * @drawable false
130
+ * @example
131
+ * ```typescript
132
+ * const inside = bitbybit.logic.thresholdGapsBooleanList({
133
+ * numbers: [0.2, 0.5, 0.8],
134
+ * gapThresholds: [[0.3, 0.6], [0.7, 0.9]],
135
+ * inverse: false,
136
+ * });
137
+ * ```
103
138
  */
104
139
  thresholdGapsBooleanList(inputs) {
105
140
  const booleans = [];
@@ -123,10 +158,11 @@ export class Logic {
123
158
  return booleans;
124
159
  }
125
160
  /**
126
- * Applies NOT operator to flip a boolean value.
127
- * Example: true → false, false → true
128
- * @param inputs a true or false boolean
129
- * @returns boolean
161
+ * Flips a boolean: true becomes false and false becomes true.
162
+ *
163
+ * Example: true -> false
164
+ * @param inputs - The boolean
165
+ * @returns The opposite boolean
130
166
  * @group edit
131
167
  * @shortname not
132
168
  * @drawable false
@@ -135,10 +171,11 @@ export class Logic {
135
171
  return !inputs.boolean;
136
172
  }
137
173
  /**
138
- * Applies NOT operator to flip all boolean values in a list.
139
- * Example: [true, false, true] → [false, true, false]
140
- * @param inputs a list of true or false booleans
141
- * @returns booleans
174
+ * Flips every boolean in a list.
175
+ *
176
+ * Example: [true, false, true] -> [false, true, false]
177
+ * @param inputs - The booleans
178
+ * @returns The flipped booleans, in the same order
142
179
  * @group edit
143
180
  * @shortname not list
144
181
  * @drawable false
@@ -147,13 +184,19 @@ export class Logic {
147
184
  return inputs.booleans.map(b => !b);
148
185
  }
149
186
  /**
150
- * Compares two values using various operators (==, !=, ===, !==, <, <=, >, >=).
151
- * Example: 5 > 3 → true, 'hello' === 'world' → false
152
- * @param inputs two values to be compared
153
- * @returns Result of the comparison
187
+ * Compares two values with an operator: less, less or equal, greater, greater or equal, equal
188
+ * or not equal, in the loose (`==`) or strict (`===`) form.
189
+ *
190
+ * Example: 5 greater than 3 -> true; 'hello' strictly equal to 'world' -> false
191
+ * @param inputs - The two values and the operator
192
+ * @returns The result of the comparison
154
193
  * @group operations
155
194
  * @shortname compare
156
195
  * @drawable false
196
+ * @example
197
+ * ```typescript
198
+ * const bigger = bitbybit.logic.compare({ first: 5, second: 3, operator: Bit.Inputs.Logic.BooleanOperatorsEnum.greater });
199
+ * ```
157
200
  */
158
201
  compare(inputs) {
159
202
  switch (inputs.operator) {
@@ -178,25 +221,35 @@ export class Logic {
178
221
  }
179
222
  }
180
223
  /**
181
- * Conditionally passes a value through if boolean is true, otherwise returns undefined.
182
- * Example: value=42, boolean=true → 42, value=42, boolean=false → undefined
183
- * @param inputs a value and a boolean value
184
- * @returns value or undefined
224
+ * Lets a value through when the boolean is true and gives undefined when it is false.
225
+ *
226
+ * Example: 42 with true -> 42; 42 with false -> undefined
227
+ * @param inputs - The value and the boolean that opens the gate
228
+ * @returns The value, or undefined when the gate is closed
185
229
  * @group operations
186
230
  * @shortname value gate
187
231
  * @drawable false
232
+ * @example
233
+ * ```typescript
234
+ * const maybe = bitbybit.logic.valueGate({ value: 42, boolean: true });
235
+ * ```
188
236
  */
189
237
  valueGate(inputs) {
190
238
  return inputs.boolean ? inputs.value : undefined;
191
239
  }
192
240
  /**
193
- * Returns the first defined (non-undefined) value from two options (fallback pattern).
194
- * Example: value1=42, value2=10 → 42, value1=undefined, value2=10 → 10
195
- * @param inputs two values
196
- * @returns value or undefined
241
+ * Picks the first of two values that is defined, so the second acts as a fallback.
242
+ *
243
+ * Example: 42 and 10 -> 42; undefined and 10 -> 10
244
+ * @param inputs - The preferred value and the fallback
245
+ * @returns The first defined value, or undefined when both are missing
197
246
  * @group operations
198
247
  * @shortname first defined value gate
199
248
  * @drawable false
249
+ * @example
250
+ * ```typescript
251
+ * const chosen = bitbybit.logic.firstDefinedValueGate({ value1: undefined, value2: 10 });
252
+ * ```
200
253
  */
201
254
  firstDefinedValueGate(inputs) {
202
255
  let res;