@promptbook/editable 0.102.0-11 → 0.102.0-16

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 (30) hide show
  1. package/esm/index.es.js +915 -1
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/color.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/components.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  6. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  7. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +5 -1
  8. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +4 -0
  9. package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +43 -5
  10. package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +6 -2
  11. package/esm/typings/src/book-components/Chat/save/index.d.ts +38 -8
  12. package/esm/typings/src/book-components/Chat/save/json/jsonSaveFormatDefinition.d.ts +6 -2
  13. package/esm/typings/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -1
  14. package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +6 -2
  15. package/esm/typings/src/book-components/Chat/save/react/reactSaveFormatDefinition.d.ts +16 -0
  16. package/esm/typings/src/book-components/Chat/save/text/txtSaveFormatDefinition.d.ts +5 -1
  17. package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  18. package/esm/typings/src/book-components/icons/SaveIcon.d.ts +10 -0
  19. package/esm/typings/src/config.d.ts +26 -4
  20. package/esm/typings/src/utils/color/Color.d.ts +8 -0
  21. package/esm/typings/src/utils/color/operators/darken.d.ts +2 -1
  22. package/esm/typings/src/utils/color/operators/grayscale.d.ts +2 -1
  23. package/esm/typings/src/utils/color/operators/lighten.d.ts +2 -1
  24. package/esm/typings/src/utils/color/operators/mixWithColor.d.ts +2 -1
  25. package/esm/typings/src/utils/color/operators/saturate.d.ts +13 -0
  26. package/esm/typings/src/utils/serialization/serializeToPromptbookJavascript.d.ts +22 -0
  27. package/esm/typings/src/version.d.ts +1 -1
  28. package/package.json +2 -2
  29. package/umd/index.umd.js +915 -1
  30. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -23,12 +23,901 @@
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- const PROMPTBOOK_ENGINE_VERSION = '0.102.0-11';
26
+ const PROMPTBOOK_ENGINE_VERSION = '0.102.0-16';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
30
30
  */
31
31
 
32
+ /**
33
+ * @private util of `@promptbook/color`
34
+ * @de
35
+ */
36
+ class TakeChain {
37
+ constructor(value) {
38
+ this.value = value;
39
+ }
40
+ then(callback) {
41
+ const newValue = callback(this.value);
42
+ return take(newValue);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * A function that takes an initial value and returns a proxy object with chainable methods.
48
+ *
49
+ * @param {*} initialValue - The initial value.
50
+ * @returns {Proxy<WithTake<TValue>>} - A proxy object with a `take` method.
51
+ *
52
+ * @private util of `@promptbook/color`
53
+ * @deprecated [🤡] Use some better functional library instead of `TakeChain`
54
+ */
55
+ function take(initialValue) {
56
+ if (initialValue instanceof TakeChain) {
57
+ return initialValue;
58
+ }
59
+ return new Proxy(new TakeChain(initialValue), {
60
+ get(target, property, receiver) {
61
+ if (Reflect.has(target, property)) {
62
+ return Reflect.get(target, property, receiver);
63
+ }
64
+ else if (Reflect.has(initialValue, property)) {
65
+ return Reflect.get(initialValue, property, receiver);
66
+ }
67
+ else {
68
+ return undefined;
69
+ }
70
+ },
71
+ });
72
+ }
73
+
74
+ /**
75
+ * 🎨 List of all 140 color names which are supported by CSS
76
+ *
77
+ * @public exported from `@promptbook/color`
78
+ */
79
+ const CSS_COLORS = {
80
+ transparent: 'rgba(0,0,0,0)',
81
+ aliceblue: '#f0f8ff',
82
+ antiquewhite: '#faebd7',
83
+ aqua: '#00ffff',
84
+ aquamarine: '#7fffd4',
85
+ azure: '#f0ffff',
86
+ beige: '#f5f5dc',
87
+ bisque: '#ffe4c4',
88
+ black: '#000000',
89
+ blanchedalmond: '#ffebcd',
90
+ blue: '#0000ff',
91
+ blueviolet: '#8a2be2',
92
+ brown: '#a52a2a',
93
+ burlywood: '#deb887',
94
+ cadetblue: '#5f9ea0',
95
+ chartreuse: '#7fff00',
96
+ chocolate: '#d2691e',
97
+ coral: '#ff7f50',
98
+ cornflowerblue: '#6495ed',
99
+ cornsilk: '#fff8dc',
100
+ crimson: '#dc143c',
101
+ cyan: '#00ffff',
102
+ darkblue: '#00008b',
103
+ darkcyan: '#008b8b',
104
+ darkgoldenrod: '#b8860b',
105
+ darkgray: '#a9a9a9',
106
+ darkgrey: '#a9a9a9',
107
+ darkgreen: '#006400',
108
+ darkkhaki: '#bdb76b',
109
+ darkmagenta: '#8b008b',
110
+ darkolivegreen: '#556b2f',
111
+ darkorange: '#ff8c00',
112
+ darkorchid: '#9932cc',
113
+ darkred: '#8b0000',
114
+ darksalmon: '#e9967a',
115
+ darkseagreen: '#8fbc8f',
116
+ darkslateblue: '#483d8b',
117
+ darkslategray: '#2f4f4f',
118
+ darkslategrey: '#2f4f4f',
119
+ darkturquoise: '#00ced1',
120
+ darkviolet: '#9400d3',
121
+ deeppink: '#ff1493',
122
+ deepskyblue: '#00bfff',
123
+ dimgray: '#696969',
124
+ dimgrey: '#696969',
125
+ dodgerblue: '#1e90ff',
126
+ firebrick: '#b22222',
127
+ floralwhite: '#fffaf0',
128
+ forestgreen: '#228b22',
129
+ fuchsia: '#ff00ff',
130
+ gainsboro: '#dcdcdc',
131
+ ghostwhite: '#f8f8ff',
132
+ gold: '#ffd700',
133
+ goldenrod: '#daa520',
134
+ gray: '#808080',
135
+ grey: '#808080',
136
+ green: '#008000',
137
+ greenyellow: '#adff2f',
138
+ honeydew: '#f0fff0',
139
+ hotpink: '#ff69b4',
140
+ indianred: '#cd5c5c',
141
+ indigo: '#4b0082',
142
+ ivory: '#fffff0',
143
+ khaki: '#f0e68c',
144
+ lavender: '#e6e6fa',
145
+ lavenderblush: '#fff0f5',
146
+ lawngreen: '#7cfc00',
147
+ lemonchiffon: '#fffacd',
148
+ lightblue: '#add8e6',
149
+ lightcoral: '#f08080',
150
+ lightcyan: '#e0ffff',
151
+ lightgoldenrodyellow: '#fafad2',
152
+ lightgray: '#d3d3d3',
153
+ lightgrey: '#d3d3d3',
154
+ lightgreen: '#90ee90',
155
+ lightpink: '#ffb6c1',
156
+ lightsalmon: '#ffa07a',
157
+ lightseagreen: '#20b2aa',
158
+ lightskyblue: '#87cefa',
159
+ lightslategray: '#778899',
160
+ lightslategrey: '#778899',
161
+ lightsteelblue: '#b0c4de',
162
+ lightyellow: '#ffffe0',
163
+ lime: '#00ff00',
164
+ limegreen: '#32cd32',
165
+ linen: '#faf0e6',
166
+ magenta: '#ff00ff',
167
+ maroon: '#800000',
168
+ mediumaquamarine: '#66cdaa',
169
+ mediumblue: '#0000cd',
170
+ mediumorchid: '#ba55d3',
171
+ mediumpurple: '#9370db',
172
+ mediumseagreen: '#3cb371',
173
+ mediumslateblue: '#7b68ee',
174
+ mediumspringgreen: '#00fa9a',
175
+ mediumturquoise: '#48d1cc',
176
+ mediumvioletred: '#c71585',
177
+ midnightblue: '#191970',
178
+ mintcream: '#f5fffa',
179
+ mistyrose: '#ffe4e1',
180
+ moccasin: '#ffe4b5',
181
+ navajowhite: '#ffdead',
182
+ navy: '#000080',
183
+ oldlace: '#fdf5e6',
184
+ olive: '#808000',
185
+ olivedrab: '#6b8e23',
186
+ orange: '#ffa500',
187
+ orangered: '#ff4500',
188
+ orchid: '#da70d6',
189
+ palegoldenrod: '#eee8aa',
190
+ palegreen: '#98fb98',
191
+ paleturquoise: '#afeeee',
192
+ palevioletred: '#db7093',
193
+ papayawhip: '#ffefd5',
194
+ peachpuff: '#ffdab9',
195
+ peru: '#cd853f',
196
+ pink: '#ffc0cb',
197
+ plum: '#dda0dd',
198
+ powderblue: '#b0e0e6',
199
+ purple: '#800080',
200
+ rebeccapurple: '#663399',
201
+ red: '#ff0000',
202
+ rosybrown: '#bc8f8f',
203
+ royalblue: '#4169e1',
204
+ saddlebrown: '#8b4513',
205
+ salmon: '#fa8072',
206
+ sandybrown: '#f4a460',
207
+ seagreen: '#2e8b57',
208
+ seashell: '#fff5ee',
209
+ sienna: '#a0522d',
210
+ silver: '#c0c0c0',
211
+ skyblue: '#87ceeb',
212
+ slateblue: '#6a5acd',
213
+ slategray: '#708090',
214
+ slategrey: '#708090',
215
+ snow: '#fffafa',
216
+ springgreen: '#00ff7f',
217
+ steelblue: '#4682b4',
218
+ tan: '#d2b48c',
219
+ teal: '#008080',
220
+ thistle: '#d8bfd8',
221
+ tomato: '#ff6347',
222
+ turquoise: '#40e0d0',
223
+ violet: '#ee82ee',
224
+ wheat: '#f5deb3',
225
+ white: '#ffffff',
226
+ whitesmoke: '#f5f5f5',
227
+ yellow: '#ffff00',
228
+ yellowgreen: '#9acd32',
229
+ };
230
+ /**
231
+ * Note: [💞] Ignore a discrepancy between file name and entity name
232
+ */
233
+
234
+ /**
235
+ * Validates that a channel value is a valid number within the range of 0 to 255.
236
+ * Throws an error if the value is not valid.
237
+ *
238
+ * @param channelName - The name of the channel being validated.
239
+ * @param value - The value of the channel to validate.
240
+ * @throws Will throw an error if the value is not a valid channel number.
241
+ *
242
+ * @private util of `@promptbook/color`
243
+ */
244
+ function checkChannelValue(channelName, value) {
245
+ if (typeof value !== 'number') {
246
+ throw new Error(`${channelName} channel value is not number but ${typeof value}`);
247
+ }
248
+ if (isNaN(value)) {
249
+ throw new Error(`${channelName} channel value is NaN`);
250
+ }
251
+ if (Math.round(value) !== value) {
252
+ throw new Error(`${channelName} channel is not whole number, it is ${value}`);
253
+ }
254
+ if (value < 0) {
255
+ throw new Error(`${channelName} channel is lower than 0, it is ${value}`);
256
+ }
257
+ if (value > 255) {
258
+ throw new Error(`${channelName} channel is greater than 255, it is ${value}`);
259
+ }
260
+ }
261
+ /**
262
+ * TODO: [🧠][🚓] Is/which combination it better to use asserts/check, validate or is utility function?
263
+ */
264
+
265
+ /**
266
+ * Color object represents an RGB color with alpha channel
267
+ *
268
+ * Note: There is no fromObject/toObject because the most logical way to serialize color is as a hex string (#009edd)
269
+ *
270
+ * @public exported from `@promptbook/color`
271
+ */
272
+ class Color {
273
+ /**
274
+ * Creates a new Color instance from miscellaneous formats
275
+ * - It can receive Color instance and just return the same instance
276
+ * - It can receive color in string format for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)`
277
+ *
278
+ * Note: This is not including fromImage because detecting color from an image is heavy task which requires async stuff and we cannot safely determine with overloading if return value will be a promise
279
+ *
280
+ * @param color
281
+ * @returns Color object
282
+ */
283
+ static from(color) {
284
+ if (color instanceof Color) {
285
+ return take(color);
286
+ }
287
+ else if (Color.isColor(color)) {
288
+ return take(color);
289
+ }
290
+ else if (typeof color === 'string') {
291
+ return Color.fromString(color);
292
+ }
293
+ else {
294
+ console.error({ color });
295
+ throw new Error(`Can not create color from given object`);
296
+ }
297
+ }
298
+ /**
299
+ * Creates a new Color instance from miscellaneous string formats
300
+ *
301
+ * @param color as a string for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)`, `red`, `darkgrey`,...
302
+ * @returns Color object
303
+ */
304
+ static fromString(color) {
305
+ if (CSS_COLORS[color]) {
306
+ return Color.fromString(CSS_COLORS[color]);
307
+ // -----
308
+ }
309
+ else if (Color.isHexColorString(color)) {
310
+ return Color.fromHex(color);
311
+ // -----
312
+ }
313
+ else if (/^hsl\(\s*(\d+)\s*,\s*(\d+(?:\.\d+)?%)\s*,\s*(\d+(?:\.\d+)?%)\)$/.test(color)) {
314
+ return Color.fromHsl(color);
315
+ // -----
316
+ }
317
+ else if (/^rgb\((\s*[0-9-.%]+\s*,?){3}\)$/.test(color)) {
318
+ // TODO: [0] Should be fromRgbString and fromRgbaString one or two functions
319
+ return Color.fromRgbString(color);
320
+ // -----
321
+ }
322
+ else if (/^rgba\((\s*[0-9-.%]+\s*,?){4}\)$/.test(color)) {
323
+ return Color.fromRgbaString(color);
324
+ // -----
325
+ }
326
+ else {
327
+ throw new Error(`Can not create a new Color instance from string "${color}".`);
328
+ }
329
+ }
330
+ /**
331
+ * Gets common color
332
+ *
333
+ * @param key as a css string like `midnightblue`
334
+ * @returns Color object
335
+ */
336
+ static get(key) {
337
+ if (!CSS_COLORS[key]) {
338
+ throw new Error(`"${key}" is not a common css color.`);
339
+ }
340
+ return Color.fromString(CSS_COLORS[key]);
341
+ }
342
+ /**
343
+ * Creates a new Color instance from average color of given image
344
+ *
345
+ * @param image as a source for example `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdjYJh39z8ABJgCe/ZvAS4AAAAASUVORK5CYII=`
346
+ * @returns Color object
347
+ */
348
+ static async fromImage(image) {
349
+ return Color.fromHex(`#009edd`);
350
+ }
351
+ /**
352
+ * Creates a new Color instance from color in hex format
353
+ *
354
+ * @param color in hex for example `#009edd`, `009edd`, `#555`,...
355
+ * @returns Color object
356
+ */
357
+ static fromHex(hex) {
358
+ const hexOriginal = hex;
359
+ if (hex.startsWith('#')) {
360
+ hex = hex.substring(1);
361
+ }
362
+ if (hex.length === 3) {
363
+ return Color.fromHex3(hex);
364
+ }
365
+ if (hex.length === 6) {
366
+ return Color.fromHex6(hex);
367
+ }
368
+ if (hex.length === 8) {
369
+ return Color.fromHex8(hex);
370
+ }
371
+ throw new Error(`Can not parse color from hex string "${hexOriginal}"`);
372
+ }
373
+ /**
374
+ * Creates a new Color instance from color in hex format with 3 color digits (without alpha channel)
375
+ *
376
+ * @param color in hex for example `09d`
377
+ * @returns Color object
378
+ */
379
+ static fromHex3(hex) {
380
+ const r = parseInt(hex.substr(0, 1), 16) * 16;
381
+ const g = parseInt(hex.substr(1, 1), 16) * 16;
382
+ const b = parseInt(hex.substr(2, 1), 16) * 16;
383
+ return take(new Color(r, g, b));
384
+ }
385
+ /**
386
+ * Creates a new Color instance from color in hex format with 6 color digits (without alpha channel)
387
+ *
388
+ * @param color in hex for example `009edd`
389
+ * @returns Color object
390
+ */
391
+ static fromHex6(hex) {
392
+ const r = parseInt(hex.substr(0, 2), 16);
393
+ const g = parseInt(hex.substr(2, 2), 16);
394
+ const b = parseInt(hex.substr(4, 2), 16);
395
+ return take(new Color(r, g, b));
396
+ }
397
+ /**
398
+ * Creates a new Color instance from color in hex format with 8 color digits (with alpha channel)
399
+ *
400
+ * @param color in hex for example `009edd`
401
+ * @returns Color object
402
+ */
403
+ static fromHex8(hex) {
404
+ const r = parseInt(hex.substr(0, 2), 16);
405
+ const g = parseInt(hex.substr(2, 2), 16);
406
+ const b = parseInt(hex.substr(4, 2), 16);
407
+ const a = parseInt(hex.substr(6, 2), 16);
408
+ return take(new Color(r, g, b, a));
409
+ }
410
+ /**
411
+ * Creates a new Color instance from color in hsl format
412
+ *
413
+ * @param color as a hsl for example `hsl(197.1,100%,43.3%)`
414
+ * @returns Color object
415
+ */
416
+ static fromHsl(hsl) {
417
+ const match = hsl.match(/^hsl\(\s*([0-9.]+)\s*,\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*\)$/);
418
+ if (!match) {
419
+ throw new Error(`Invalid hsl string format: "${hsl}"`);
420
+ }
421
+ const h = parseFloat(match[1]);
422
+ const s = parseFloat(match[2]) / 100;
423
+ const l = parseFloat(match[3]) / 100;
424
+ // HSL to RGB conversion
425
+ const c = (1 - Math.abs(2 * l - 1)) * s;
426
+ const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
427
+ const m = l - c / 2;
428
+ let r1 = 0, g1 = 0, b1 = 0;
429
+ if (h >= 0 && h < 60) {
430
+ r1 = c;
431
+ g1 = x;
432
+ b1 = 0;
433
+ }
434
+ else if (h >= 60 && h < 120) {
435
+ r1 = x;
436
+ g1 = c;
437
+ b1 = 0;
438
+ }
439
+ else if (h >= 120 && h < 180) {
440
+ r1 = 0;
441
+ g1 = c;
442
+ b1 = x;
443
+ }
444
+ else if (h >= 180 && h < 240) {
445
+ r1 = 0;
446
+ g1 = x;
447
+ b1 = c;
448
+ }
449
+ else if (h >= 240 && h < 300) {
450
+ r1 = x;
451
+ g1 = 0;
452
+ b1 = c;
453
+ }
454
+ else if (h >= 300 && h < 360) {
455
+ r1 = c;
456
+ g1 = 0;
457
+ b1 = x;
458
+ }
459
+ const r = Math.round((r1 + m) * 255);
460
+ const g = Math.round((g1 + m) * 255);
461
+ const b = Math.round((b1 + m) * 255);
462
+ return take(new Color(r, g, b));
463
+ }
464
+ /**
465
+ * Creates a new Color instance from color in rgb format
466
+ *
467
+ * @param color as a rgb for example `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`
468
+ * @returns Color object
469
+ */
470
+ static fromRgbString(rgb) {
471
+ const match = rgb.match(/^rgb\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/);
472
+ if (!match) {
473
+ throw new Error(`Invalid rgb string format: "${rgb}"`);
474
+ }
475
+ const parseChannel = (value) => {
476
+ if (value.endsWith('%')) {
477
+ // Percentage value
478
+ const percent = parseFloat(value);
479
+ return Math.round((percent / 100) * 255);
480
+ }
481
+ else {
482
+ // Numeric value
483
+ return Math.round(parseFloat(value));
484
+ }
485
+ };
486
+ const r = parseChannel(match[1]);
487
+ const g = parseChannel(match[2]);
488
+ const b = parseChannel(match[3]);
489
+ return take(new Color(r, g, b));
490
+ }
491
+ /**
492
+ * Creates a new Color instance from color in rbga format
493
+ *
494
+ * @param color as a rgba for example `rgba(0,158,221,0.5)`, `rgb(0%,62%,86.7%,50%)`
495
+ * @returns Color object
496
+ */
497
+ static fromRgbaString(rgba) {
498
+ const match = rgba.match(/^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/);
499
+ if (!match) {
500
+ throw new Error(`Invalid rgba string format: "${rgba}"`);
501
+ }
502
+ const parseChannel = (value) => {
503
+ if (value.endsWith('%')) {
504
+ const percent = parseFloat(value);
505
+ return Math.round((percent / 100) * 255);
506
+ }
507
+ else {
508
+ return Math.round(parseFloat(value));
509
+ }
510
+ };
511
+ const parseAlpha = (value) => {
512
+ if (value.endsWith('%')) {
513
+ const percent = parseFloat(value);
514
+ return Math.round((percent / 100) * 255);
515
+ }
516
+ else {
517
+ const alphaFloat = parseFloat(value);
518
+ // If alpha is between 0 and 1, treat as float
519
+ if (alphaFloat <= 1) {
520
+ return Math.round(alphaFloat * 255);
521
+ }
522
+ // Otherwise, treat as 0-255
523
+ return Math.round(alphaFloat);
524
+ }
525
+ };
526
+ const r = parseChannel(match[1]);
527
+ const g = parseChannel(match[2]);
528
+ const b = parseChannel(match[3]);
529
+ const a = parseAlpha(match[4]);
530
+ return take(new Color(r, g, b, a));
531
+ }
532
+ /**
533
+ * Creates a new Color for color channels values
534
+ *
535
+ * @param red number from 0 to 255
536
+ * @param green number from 0 to 255
537
+ * @param blue number from 0 to 255
538
+ * @param alpha number from 0 (transparent) to 255 (opaque = default)
539
+ * @returns Color object
540
+ */
541
+ static fromValues(red, green, blue, alpha = 255) {
542
+ return take(new Color(red, green, blue, alpha));
543
+ }
544
+ /**
545
+ * Checks if the given value is a valid Color object.
546
+ *
547
+ * @param {unknown} value - The value to check.
548
+ * @return {value is WithTake<Color>} Returns true if the value is a valid Color object, false otherwise.
549
+ */
550
+ static isColor(value) {
551
+ if (typeof value !== 'object') {
552
+ return false;
553
+ }
554
+ if (value === null) {
555
+ return false;
556
+ }
557
+ if (typeof value.red !== 'number' ||
558
+ typeof value.green !== 'number' ||
559
+ typeof value.blue !== 'number' ||
560
+ typeof value.alpha !== 'number') {
561
+ return false;
562
+ }
563
+ if (typeof value.then !== 'function') {
564
+ return false;
565
+ }
566
+ return true;
567
+ }
568
+ /**
569
+ * Checks if the given value is a valid hex color string
570
+ *
571
+ * @param value - value to check
572
+ * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
573
+ */
574
+ static isHexColorString(value) {
575
+ return typeof value === 'string' && /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(value);
576
+ }
577
+ /**
578
+ * Creates new Color object
579
+ *
580
+ * Note: Consider using one of static methods like `from` or `fromString`
581
+ *
582
+ * @param red number from 0 to 255
583
+ * @param green number from 0 to 255
584
+ * @param blue number from 0 to 255
585
+ * @param alpha number from 0 (transparent) to 255 (opaque)
586
+ */
587
+ constructor(red, green, blue, alpha = 255) {
588
+ this.red = red;
589
+ this.green = green;
590
+ this.blue = blue;
591
+ this.alpha = alpha;
592
+ checkChannelValue('Red', red);
593
+ checkChannelValue('Green', green);
594
+ checkChannelValue('Blue', blue);
595
+ checkChannelValue('Alpha', alpha);
596
+ }
597
+ /**
598
+ * Shortcut for `red` property
599
+ * Number from 0 to 255
600
+ * @alias red
601
+ */
602
+ get r() {
603
+ return this.red;
604
+ }
605
+ /**
606
+ * Shortcut for `green` property
607
+ * Number from 0 to 255
608
+ * @alias green
609
+ */
610
+ get g() {
611
+ return this.green;
612
+ }
613
+ /**
614
+ * Shortcut for `blue` property
615
+ * Number from 0 to 255
616
+ * @alias blue
617
+ */
618
+ get b() {
619
+ return this.blue;
620
+ }
621
+ /**
622
+ * Shortcut for `alpha` property
623
+ * Number from 0 (transparent) to 255 (opaque)
624
+ * @alias alpha
625
+ */
626
+ get a() {
627
+ return this.alpha;
628
+ }
629
+ /**
630
+ * Shortcut for `alpha` property
631
+ * Number from 0 (transparent) to 255 (opaque)
632
+ * @alias alpha
633
+ */
634
+ get opacity() {
635
+ return this.alpha;
636
+ }
637
+ /**
638
+ * Shortcut for 1-`alpha` property
639
+ */
640
+ get transparency() {
641
+ return 255 - this.alpha;
642
+ }
643
+ clone() {
644
+ return take(new Color(this.red, this.green, this.blue, this.alpha));
645
+ }
646
+ toString() {
647
+ return this.toHex();
648
+ }
649
+ toHex() {
650
+ if (this.alpha === 255) {
651
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
652
+ .toString(16)
653
+ .padStart(2, '0')}`;
654
+ }
655
+ else {
656
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
657
+ .toString(16)
658
+ .padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
659
+ }
660
+ }
661
+ toRgb() {
662
+ if (this.alpha === 255) {
663
+ return `rgb(${this.red}, ${this.green}, ${this.blue})`;
664
+ }
665
+ else {
666
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
667
+ }
668
+ }
669
+ toHsl() {
670
+ throw new Error(`Getting HSL is not implemented`);
671
+ }
672
+ }
673
+ /**
674
+ * TODO: [🥻] Split Color class and color type
675
+ * TODO: For each method a corresponding static method should be created
676
+ * Like clone can be done by color.clone() OR Color.clone(color)
677
+ * TODO: Probably as an independent LIB OR add to LIB xyzt (ask @roseckyj)
678
+ * TODO: !! Transfer back to Collboard (whole directory)
679
+ * TODO: Maybe [🏌️‍♂️] change ACRY toString => (toHex) toRgb when there will be toRgb and toRgba united
680
+ * TODO: Convert getters to methods - getters only for values
681
+ * TODO: Write tests
682
+ * TODO: Getters for alpha, opacity, transparency, r, b, g, h, s, l, a,...
683
+ * TODO: [0] Should be fromRgbString and fromRgbaString one or two functions + one or two regex
684
+ * TODO: Use rgb, rgba, hsl for testing and parsing with the same regex
685
+ * TODO: Regex for rgb, rgba, hsl does not support all options like deg, rad, turn,...
686
+ * TODO: Convolution matrix
687
+ * TODO: Maybe connect with textures
688
+ */
689
+
690
+ /**
691
+ * Converts HSL values to RGB values
692
+ *
693
+ * @param hue [0-1]
694
+ * @param saturation [0-1]
695
+ * @param lightness [0-1]
696
+ * @returns [red, green, blue] [0-255]
697
+ *
698
+ * @private util of `@promptbook/color`
699
+ */
700
+ function hslToRgb(hue, saturation, lightness) {
701
+ let red;
702
+ let green;
703
+ let blue;
704
+ if (saturation === 0) {
705
+ // achromatic
706
+ red = lightness;
707
+ green = lightness;
708
+ blue = lightness;
709
+ }
710
+ else {
711
+ // TODO: Extract to separate function
712
+ const hue2rgb = (p, q, t) => {
713
+ if (t < 0)
714
+ t += 1;
715
+ if (t > 1)
716
+ t -= 1;
717
+ if (t < 1 / 6)
718
+ return p + (q - p) * 6 * t;
719
+ if (t < 1 / 2)
720
+ return q;
721
+ if (t < 2 / 3)
722
+ return p + (q - p) * (2 / 3 - t) * 6;
723
+ return p;
724
+ };
725
+ const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
726
+ const p = 2 * lightness - q;
727
+ red = hue2rgb(p, q, hue + 1 / 3);
728
+ green = hue2rgb(p, q, hue);
729
+ blue = hue2rgb(p, q, hue - 1 / 3);
730
+ }
731
+ return [Math.round(red * 255), Math.round(green * 255), Math.round(blue * 255)];
732
+ }
733
+ /**
734
+ * TODO: Properly name all used internal variables
735
+ */
736
+
737
+ /**
738
+ * Converts RGB values to HSL values
739
+ *
740
+ * @param red [0-255]
741
+ * @param green [0-255]
742
+ * @param blue [0-255]
743
+ * @returns [hue, saturation, lightness] [0-1]
744
+ *
745
+ * @private util of `@promptbook/color`
746
+ */
747
+ function rgbToHsl(red, green, blue) {
748
+ red /= 255;
749
+ green /= 255;
750
+ blue /= 255;
751
+ const max = Math.max(red, green, blue);
752
+ const min = Math.min(red, green, blue);
753
+ let hue;
754
+ let saturation;
755
+ const lightness = (max + min) / 2;
756
+ if (max === min) {
757
+ // achromatic
758
+ hue = 0;
759
+ saturation = 0;
760
+ }
761
+ else {
762
+ const d = max - min;
763
+ saturation = lightness > 0.5 ? d / (2 - max - min) : d / (max + min);
764
+ switch (max) {
765
+ case red:
766
+ hue = (green - blue) / d + (green < blue ? 6 : 0);
767
+ break;
768
+ case green:
769
+ hue = (blue - red) / d + 2;
770
+ break;
771
+ case blue:
772
+ hue = (red - green) / d + 4;
773
+ break;
774
+ default:
775
+ hue = 0;
776
+ }
777
+ hue /= 6;
778
+ }
779
+ return [hue, saturation, lightness];
780
+ }
781
+ /**
782
+ * TODO: Properly name all used internal variables
783
+ */
784
+
785
+ /**
786
+ * Makes color transformer which lighten the given color
787
+ *
788
+ * @param amount from 0 to 1
789
+ *
790
+ * @public exported from `@promptbook/color`
791
+ */
792
+ function lighten(amount) {
793
+ return ({ red, green, blue, alpha }) => {
794
+ const [h, s, lInitial] = rgbToHsl(red, green, blue);
795
+ let l = lInitial + amount;
796
+ l = Math.max(0, Math.min(l, 1)); // Replace lodash clamp with Math.max and Math.min
797
+ const [r, g, b] = hslToRgb(h, s, l);
798
+ return Color.fromValues(r, g, b, alpha);
799
+ };
800
+ }
801
+ /**
802
+ * TODO: Maybe implement by mix+hsl
803
+ */
804
+
805
+ /**
806
+ * Calculates distance between two colors
807
+ *
808
+ * @param color1 first color
809
+ * @param color2 second color
810
+ *
811
+ * Note: This function is inefficient. Use colorDistanceSquared instead if possible.
812
+ *
813
+ * @public exported from `@promptbook/color`
814
+ */
815
+ /**
816
+ * Calculates distance between two colors without square root
817
+ *
818
+ * @param color1 first color
819
+ * @param color2 second color
820
+ *
821
+ * @public exported from `@promptbook/color`
822
+ */
823
+ function colorDistanceSquared(color1, color2) {
824
+ const rmean = (color1.red + color2.red) / 2;
825
+ const r = color1.red - color2.red;
826
+ const g = color1.green - color2.green;
827
+ const b = color1.blue - color2.blue;
828
+ const weightR = 2 + rmean / 256;
829
+ const weightG = 4.0;
830
+ const weightB = 2 + (255 - rmean) / 256;
831
+ const distance = weightR * r * r + weightG * g * g + weightB * b * b;
832
+ return distance;
833
+ }
834
+
835
+ /**
836
+ * Makes color transformer which finds the nearest color from the given list
837
+ *
838
+ * @param colors array of colors to choose from
839
+ *
840
+ * @public exported from `@promptbook/color`
841
+ */
842
+ function nearest(...colors) {
843
+ return (color) => {
844
+ const distances = colors.map((c) => colorDistanceSquared(c, color));
845
+ const minDistance = Math.min(...distances);
846
+ const minIndex = distances.indexOf(minDistance);
847
+ const nearestColor = colors[minIndex];
848
+ return nearestColor;
849
+ };
850
+ }
851
+
852
+ /**
853
+ * Color transformer which returns the negative color
854
+ *
855
+ * @public exported from `@promptbook/color`
856
+ */
857
+ function negative(color) {
858
+ const r = 255 - color.red;
859
+ const g = 255 - color.green;
860
+ const b = 255 - color.blue;
861
+ return Color.fromValues(r, g, b, color.alpha);
862
+ }
863
+
864
+ /**
865
+ * Makes color transformer which finds the furthest color from the given list
866
+ *
867
+ * @param colors array of colors to choose from
868
+ *
869
+ * @public exported from `@promptbook/color`
870
+ */
871
+ function furthest(...colors) {
872
+ return (color) => {
873
+ const furthestColor = negative(nearest(...colors.map(negative))(color));
874
+ return furthestColor;
875
+ };
876
+ }
877
+ /**
878
+ * Makes color transformer which finds the best text color (black or white) for the given background color
879
+ *
880
+ * @public exported from `@promptbook/color`
881
+ */
882
+ furthest(Color.get('white'), Color.from('black'));
883
+
884
+ /**
885
+ * Makes color transformer which returns a grayscale version of the color
886
+ *
887
+ * @param amount from 0 to 1
888
+ *
889
+ * @public exported from `@promptbook/color`
890
+ */
891
+ function grayscale(amount) {
892
+ return ({ red, green, blue, alpha }) => {
893
+ const average = (red + green + blue) / 3;
894
+ red = Math.round(average * amount + red * (1 - amount));
895
+ green = Math.round(average * amount + green * (1 - amount));
896
+ blue = Math.round(average * amount + blue * (1 - amount));
897
+ return Color.fromValues(red, green, blue, alpha);
898
+ };
899
+ }
900
+
901
+ /**
902
+ * Makes color transformer which saturate the given color
903
+ *
904
+ * @param amount from -1 to 1
905
+ *
906
+ * @public exported from `@promptbook/color`
907
+ */
908
+ function saturate(amount) {
909
+ return ({ red, green, blue, alpha }) => {
910
+ const [h, sInitial, l] = rgbToHsl(red, green, blue);
911
+ let s = sInitial + amount;
912
+ s = Math.max(0, Math.min(s, 1));
913
+ const [r, g, b] = hslToRgb(h, s, l);
914
+ return Color.fromValues(r, g, b, alpha);
915
+ };
916
+ }
917
+ /**
918
+ * TODO: Maybe implement by mix+hsl
919
+ */
920
+
32
921
  /**
33
922
  * Returns the same value that is passed as argument.
34
923
  * No side effects.
@@ -70,6 +959,31 @@
70
959
  */
71
960
  const ADMIN_GITHUB_NAME = 'hejny';
72
961
  // <- TODO: [🐊] Pick the best claim
962
+ /**
963
+ * Color of the Promptbook
964
+ *
965
+ * TODO: [🗽] Unite branding and make single place for it
966
+ *
967
+ * @public exported from `@promptbook/core`
968
+ */
969
+ const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
970
+ // <- TODO: !!! How much is this adding to package size of @promptbook/core
971
+ /**
972
+ * Dark color of the Promptbook
973
+ *
974
+ * TODO: [🗽] Unite branding and make single place for it
975
+ *
976
+ * @public exported from `@promptbook/core`
977
+ */
978
+ PROMPTBOOK_COLOR.then(lighten(0.1)).then(saturate(0.9)).then(grayscale(0.9));
979
+ /**
980
+ * Color of the user (in chat)
981
+ *
982
+ * TODO: [🗽] Unite branding and make single place for it
983
+ *
984
+ * @public exported from `@promptbook/core`
985
+ */
986
+ Color.fromHex('#1D4ED8');
73
987
  /**
74
988
  * When the title is not provided, the default title is used
75
989
  *