@bitbybit-dev/base 1.2.0 → 1.3.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,12 +1,19 @@
1
+ /**
2
+ * Colors in the two forms the library uses: a hex text such as `#ff5733`, and an object `{ r, g, b
3
+ * }` or `{ r, g, b, a }` whose channels run either from 0 to 255 or from 0 to 1. The methods here
4
+ * build colors in each form, convert between them with an explicit channel range, read single
5
+ * channels and invert a color.
6
+ */
1
7
  export class Color {
2
8
  constructor(math) {
3
9
  this.math = math;
4
10
  }
5
11
  /**
6
- * Creates and returns a hex color string (pass-through for color input).
7
- * Example: '#FF5733' → '#FF5733'
8
- * @param inputs Color hex
9
- * @returns color string
12
+ * Passes a hex color through unchanged, so a color can be given a name and reused.
13
+ *
14
+ * Example: '#FF5733' -> '#FF5733'
15
+ * @param inputs - The hex color
16
+ * @returns The same hex color
10
17
  * @group create
11
18
  * @shortname color hex
12
19
  * @drawable false
@@ -15,9 +22,12 @@ export class Color {
15
22
  return inputs.color;
16
23
  }
17
24
  /**
18
- * Creates and returns rgb color object
19
- * @param inputs Color rgb
20
- * @returns color object
25
+ * Passes an `{ r, g, b }` color with channels from 0 to 255 through unchanged, so it can be
26
+ * given a name and reused.
27
+ *
28
+ * Example: { r: 255, g: 87, b: 51 } -> the same object
29
+ * @param inputs - The color object
30
+ * @returns The same color object
21
31
  * @group create
22
32
  * @shortname color rgb 0-255
23
33
  * @drawable false
@@ -26,9 +36,12 @@ export class Color {
26
36
  return inputs.colorRgb;
27
37
  }
28
38
  /**
29
- * Creates and returns rgb color object
30
- * @param inputs Color rgb
31
- * @returns color object
39
+ * Passes an `{ r, g, b }` color with channels from 0 to 1 through unchanged, so it can be
40
+ * given a name and reused.
41
+ *
42
+ * Example: { r: 1, g: 0.34, b: 0.2 } -> the same object
43
+ * @param inputs - The color object
44
+ * @returns The same color object
32
45
  * @group create
33
46
  * @shortname color rgb 0-1
34
47
  * @drawable false
@@ -37,9 +50,12 @@ export class Color {
37
50
  return inputs.colorRgb;
38
51
  }
39
52
  /**
40
- * Creates and returns rgba color object
41
- * @param inputs Color rgba
42
- * @returns color object
53
+ * Passes an `{ r, g, b, a }` color with color channels from 0 to 255 and opacity from 0 to 1
54
+ * through unchanged, so it can be given a name and reused.
55
+ *
56
+ * Example: { r: 255, g: 87, b: 51, a: 1 } -> the same object
57
+ * @param inputs - The color object
58
+ * @returns The same color object
43
59
  * @group create
44
60
  * @shortname color rgba 0-255
45
61
  * @drawable false
@@ -48,9 +64,12 @@ export class Color {
48
64
  return inputs.colorRgba;
49
65
  }
50
66
  /**
51
- * Creates and returns rgba color object
52
- * @param inputs Color rgba
53
- * @returns color object
67
+ * Passes an `{ r, g, b, a }` color with every channel from 0 to 1 through unchanged, so it can
68
+ * be given a name and reused.
69
+ *
70
+ * Example: { r: 1, g: 0.34, b: 0.2, a: 1 } -> the same object
71
+ * @param inputs - The color object
72
+ * @returns The same color object
54
73
  * @group create
55
74
  * @shortname color rgba 0-1
56
75
  * @drawable false
@@ -59,35 +78,53 @@ export class Color {
59
78
  return inputs.colorRgba;
60
79
  }
61
80
  /**
62
- * Creates atomic rgb color object
63
- * @param inputs Color rgb
64
- * @returns color object
81
+ * Builds an `{ r, g, b }` color from three separate channel values from 0 to 255.
82
+ *
83
+ * Example: r 255, g 87, b 51 -> { r: 255, g: 87, b: 51 }
84
+ * @param inputs - The red, green and blue values
85
+ * @returns The color object
65
86
  * @group create
66
87
  * @shortname atomic color rgb 0-255
67
88
  * @drawable false
89
+ * @example
90
+ * ```typescript
91
+ * const orange = bitbybit.color.rgbAtomic255Color({ r: 255, g: 87, b: 51 });
92
+ * ```
68
93
  */
69
94
  rgbAtomic255Color(inputs) {
70
95
  return Object.assign({}, inputs);
71
96
  }
72
97
  /**
73
- * Creates atomic rgb color object
74
- * @param inputs Color rgb
75
- * @returns color object
98
+ * Builds an `{ r, g, b }` color from three separate channel values from 0 to 1.
99
+ *
100
+ * Example: r 1, g 0.34, b 0.2 -> { r: 1, g: 0.34, b: 0.2 }
101
+ * @param inputs - The red, green and blue values
102
+ * @returns The color object
76
103
  * @group create
77
104
  * @shortname atomic color rgb 0-1
78
105
  * @drawable false
106
+ * @example
107
+ * ```typescript
108
+ * const orange = bitbybit.color.rgbAtomic1Color({ r: 1, g: 0.34, b: 0.2 });
109
+ * ```
79
110
  */
80
111
  rgbAtomic1Color(inputs) {
81
112
  return Object.assign({}, inputs);
82
113
  }
83
114
  /**
84
- * Converts hex color to RGB object with r, g, b values (0-255 range).
85
- * Example: '#FF5733' → {r: 255, g: 87, b: 51}
86
- * @param inputs Color hex
87
- * @returns rgb color
115
+ * Reads a hex color into an `{ r, g, b }` object with channels from 0 to 255.
116
+ *
117
+ * The text may start with or without `#`; anything else than six hex digits throws an error.
118
+ * Example: '#FF5733' -> { r: 255, g: 87, b: 51 }
119
+ * @param inputs - The hex color
120
+ * @returns The color object with channels from 0 to 255
88
121
  * @group convert
89
122
  * @shortname hex to rgb
90
123
  * @drawable false
124
+ * @example
125
+ * ```typescript
126
+ * const rgb = bitbybit.color.hexToRgb({ color: "#ff5733" });
127
+ * ```
91
128
  */
92
129
  hexToRgb(inputs) {
93
130
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(inputs.color);
@@ -101,14 +138,20 @@ export class Color {
101
138
  };
102
139
  }
103
140
  /**
104
- * Converts RGB values to hex color string (supports custom min/max ranges, auto-remaps to 0-255).
105
- * Example: r=255, g=87, b=51 with range [0,255] → '#ff5733'
106
- * Example: r=1, g=0.5, b=0.2 with range [0,1] → '#ff7f33'
107
- * @param inputs Color hext
108
- * @returns hex color
141
+ * Writes three channel values as a hex color.
142
+ *
143
+ * `min` and `max` say which range the values use; a range other than 0 to 255 is remapped
144
+ * first, so channels from 0 to 1 work as well.
145
+ * Example: r 255, g 87, b 51 in [0,255] -> '#ff5733'; r 1, g 0.5, b 0.2 in [0,1] -> '#ff8033'
146
+ * @param inputs - The red, green and blue values and their range
147
+ * @returns The hex color
109
148
  * @group convert
110
149
  * @shortname rgb to hex
111
150
  * @drawable false
151
+ * @example
152
+ * ```typescript
153
+ * const hex = bitbybit.color.rgbToHex({ r: 1, g: 0.5, b: 0.2, min: 0, max: 1 });
154
+ * ```
112
155
  */
113
156
  rgbToHex(inputs) {
114
157
  let r = inputs.r;
@@ -123,26 +166,38 @@ export class Color {
123
166
  return s;
124
167
  }
125
168
  /**
126
- * Converts RGB object to hex color string (supports custom min/max ranges).
127
- * Example: {r: 1, g: 0.5, b: 0.2} with range [0,1] → '#ff7f33'
128
- * @param inputs Color hext
129
- * @returns hex color string
169
+ * Writes an `{ r, g, b }` color as a hex color.
170
+ *
171
+ * `min` and `max` say which range the channels use; a range other than 0 to 255 is remapped
172
+ * first.
173
+ * Example: { r: 1, g: 0.5, b: 0.2 } in [0,1] -> '#ff8033'
174
+ * @param inputs - The color object and the range its channels use
175
+ * @returns The hex color
130
176
  * @group convert
131
177
  * @shortname rgb obj to hex
132
178
  * @drawable false
179
+ * @example
180
+ * ```typescript
181
+ * const hex = bitbybit.color.rgbObjToHex({ rgb: { r: 1, g: 0.5, b: 0.2 }, min: 0, max: 1 });
182
+ * ```
133
183
  */
134
184
  rgbObjToHex(inputs) {
135
185
  return this.rgbToHex({ r: inputs.rgb.r, g: inputs.rgb.g, b: inputs.rgb.b, min: inputs.min, max: inputs.max });
136
186
  }
137
187
  /**
138
- * Converts hex color to RGB and remaps values to a custom range.
139
- * Example: '#FF5733' mapped to [0,1] → {r: 1, g: 0.341, b: 0.2}
140
- * Example: '#FF5733' mapped to [0,100] → {r: 100, g: 34.1, b: 20}
141
- * @param inputs Color hext
142
- * @returns rgb color
188
+ * Reads a hex color into an `{ r, g, b }` object with the channels remapped to a range of your
189
+ * choice.
190
+ *
191
+ * Example: '#FF5733' mapped to [0,1] -> { r: 1, g: 0.341, b: 0.2 }
192
+ * @param inputs - The hex color and the range to map the channels to
193
+ * @returns The color object with channels in that range
143
194
  * @group convert
144
195
  * @shortname hex to rgb mapped
145
196
  * @drawable false
197
+ * @example
198
+ * ```typescript
199
+ * const rgb = bitbybit.color.hexToRgbMapped({ color: "#ff5733", from: 0, to: 1 });
200
+ * ```
146
201
  */
147
202
  hexToRgbMapped(inputs) {
148
203
  const rgb = this.hexToRgb(inputs);
@@ -153,50 +208,66 @@ export class Color {
153
208
  };
154
209
  }
155
210
  /**
156
- * Extracts the red channel value from hex color (can be mapped to custom range).
157
- * Example: '#FF5733' with range [0,1] → 1
158
- * @param inputs Color hext
159
- * @returns rgb color
211
+ * Reads the red channel of a hex color, remapped to a range of your choice.
212
+ *
213
+ * Example: '#FF5733' in [0,1] -> 1
214
+ * @param inputs - The hex color and the range to map the channel to
215
+ * @returns The red channel in that range
160
216
  * @group hex to
161
217
  * @shortname red
162
218
  * @drawable false
219
+ * @example
220
+ * ```typescript
221
+ * const red = bitbybit.color.getRedParam({ color: "#ff5733", from: 0, to: 1 });
222
+ * ```
163
223
  */
164
224
  getRedParam(inputs) {
165
225
  const rgb = this.hexToRgbMapped(inputs);
166
226
  return rgb.r;
167
227
  }
168
228
  /**
169
- * Extracts the green channel value from hex color (can be mapped to custom range).
170
- * Example: '#FF5733' with range [0,1] → 0.341
171
- * @param inputs Color hext
172
- * @returns rgb color
229
+ * Reads the green channel of a hex color, remapped to a range of your choice.
230
+ *
231
+ * Example: '#FF5733' in [0,1] -> 0.341
232
+ * @param inputs - The hex color and the range to map the channel to
233
+ * @returns The green channel in that range
173
234
  * @group hex to
174
235
  * @shortname green
175
236
  * @drawable false
237
+ * @example
238
+ * ```typescript
239
+ * const green = bitbybit.color.getGreenParam({ color: "#ff5733", from: 0, to: 1 });
240
+ * ```
176
241
  */
177
242
  getGreenParam(inputs) {
178
243
  const rgb = this.hexToRgbMapped(inputs);
179
244
  return rgb.g;
180
245
  }
181
246
  /**
182
- * Extracts the blue channel value from hex color (can be mapped to custom range).
183
- * Example: '#FF5733' with range [0,1] → 0.2
184
- * @param inputs Color hext
185
- * @returns blue param
247
+ * Reads the blue channel of a hex color, remapped to a range of your choice.
248
+ *
249
+ * Example: '#FF5733' in [0,1] -> 0.2
250
+ * @param inputs - The hex color and the range to map the channel to
251
+ * @returns The blue channel in that range
186
252
  * @group hex to
187
253
  * @shortname blue
188
254
  * @drawable false
255
+ * @example
256
+ * ```typescript
257
+ * const blue = bitbybit.color.getBlueParam({ color: "#ff5733", from: 0, to: 1 });
258
+ * ```
189
259
  */
190
260
  getBlueParam(inputs) {
191
261
  const rgb = this.hexToRgbMapped(inputs);
192
262
  return rgb.b;
193
263
  }
194
264
  /**
195
- * Extracts the red channel value from RGB object.
196
- * Example: {r: 255, g: 87, b: 51} → 255
197
- * @param inputs Color rgb
198
- * @returns red param
199
- * @group rgb to
265
+ * Reads the red channel of an `{ r, g, b }` color.
266
+ *
267
+ * Example: { r: 255, g: 87, b: 51 } -> 255
268
+ * @param inputs - The color object
269
+ * @returns The red channel, in whatever range the object uses
270
+ * @group rgb to
200
271
  * @shortname red
201
272
  * @drawable false
202
273
  */
@@ -204,10 +275,11 @@ export class Color {
204
275
  return inputs.rgb.r;
205
276
  }
206
277
  /**
207
- * Extracts the green channel value from RGB object.
208
- * Example: {r: 255, g: 87, b: 51} → 87
209
- * @param inputs Color rgb
210
- * @returns green param
278
+ * Reads the green channel of an `{ r, g, b }` color.
279
+ *
280
+ * Example: { r: 255, g: 87, b: 51 } -> 87
281
+ * @param inputs - The color object
282
+ * @returns The green channel, in whatever range the object uses
211
283
  * @group rgb to
212
284
  * @shortname green
213
285
  * @drawable false
@@ -216,10 +288,11 @@ export class Color {
216
288
  return inputs.rgb.g;
217
289
  }
218
290
  /**
219
- * Extracts the blue channel value from RGB object.
220
- * Example: {r: 255, g: 87, b: 51} → 51
221
- * @param inputs Color rgb
222
- * @returns blue param
291
+ * Reads the blue channel of an `{ r, g, b }` color.
292
+ *
293
+ * Example: { r: 255, g: 87, b: 51 } -> 51
294
+ * @param inputs - The color object
295
+ * @returns The blue channel, in whatever range the object uses
223
296
  * @group rgb to
224
297
  * @shortname blue
225
298
  * @drawable false
@@ -228,14 +301,20 @@ export class Color {
228
301
  return inputs.rgb.b;
229
302
  }
230
303
  /**
231
- * Inverts a hex color (flips RGB channels: 255-r, 255-g, 255-b).
232
- * With blackAndWhite=true → returns '#000000' or '#ffffff' based on brightness.
233
- * Example: '#FF5733' → '#00a8cc', '#FF5733' with blackAndWhite=true → '#ffffff'
234
- * @param inputs hex color and black and white option
235
- * @returns inverted color
304
+ * Inverts a hex color, turning each channel into its opposite: 255 minus the value.
305
+ *
306
+ * With `blackAndWhite` on, the result is plain black for a light color or white for a dark
307
+ * one, which suits text on a colored background.
308
+ * Example: '#FF5733' -> '#00a8cc'; with blackAndWhite -> '#ffffff'
309
+ * @param inputs - The hex color and whether to reduce the result to black or white
310
+ * @returns The inverted hex color
236
311
  * @group hex to
237
312
  * @shortname invert color
238
313
  * @drawable false
314
+ * @example
315
+ * ```typescript
316
+ * const textColor = bitbybit.color.invert({ color: "#ff5733", blackAndWhite: true });
317
+ * ```
239
318
  */
240
319
  invert(inputs) {
241
320
  const { r, g, b } = this.hexToRgbMapped({ color: inputs.color, from: 0, to: 255 });