colorino 0.13.1 → 0.14.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.
@@ -1,53 +1,5 @@
1
- function hexToRgb(hex) {
2
- const match = hex.toString().match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
3
- if (!match) {
4
- return [0, 0, 0];
5
- }
6
- let colorString = match[0];
7
- if (match[0].length === 3) {
8
- colorString = [...colorString].map((char) => char + char).join("");
9
- }
10
- const integer = parseInt(colorString, 16);
11
- const r = integer >> 16 & 255;
12
- const g = integer >> 8 & 255;
13
- const b = integer & 255;
14
- return [r, g, b];
15
- }
16
- function rgbToAnsi256(rgb) {
17
- const [r, g, b] = rgb;
18
- if (r === g && g === b) {
19
- if (r < 8) return 16;
20
- if (r > 248) return 231;
21
- return Math.round((r - 8) / 247 * 24) + 232;
22
- }
23
- return 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
24
- }
25
- function rgbToHsvValue(rgb) {
26
- const r = rgb[0] / 255;
27
- const g = rgb[1] / 255;
28
- const b = rgb[2] / 255;
29
- const v = Math.max(r, g, b);
30
- return v * 100;
31
- }
32
- function rgbToAnsi16(rgb) {
33
- const [r, g, b] = rgb;
34
- const value = rgbToHsvValue(rgb);
35
- const roundedValue = Math.round(value / 50);
36
- if (roundedValue === 0) {
37
- return 30;
38
- }
39
- let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
40
- if (roundedValue === 2) {
41
- ansi += 60;
42
- }
43
- return ansi;
44
- }
45
- const colorConverter = {
46
- hex: {
47
- toRgb: hexToRgb,
48
- toAnsi16: (hex) => rgbToAnsi16(hexToRgb(hex)),
49
- toAnsi256: (hex) => rgbToAnsi256(hexToRgb(hex))
50
- }};
1
+ const ColorinoBrowserColorized = Symbol("colorino.browserColorized");
2
+ const ColorinoBrowserObject = Symbol("colorino.browserObject");
51
3
 
52
4
  var ColorLevel = /* @__PURE__ */ ((ColorLevel2) => {
53
5
  ColorLevel2[ColorLevel2["NO_COLOR"] = 0] = "NO_COLOR";
@@ -57,147 +9,57 @@ var ColorLevel = /* @__PURE__ */ ((ColorLevel2) => {
57
9
  return ColorLevel2;
58
10
  })(ColorLevel || {});
59
11
 
60
- function isConsoleMethod(level) {
61
- return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
62
- }
63
- const ColorinoBrowserColorized = Symbol("colorino.browserColorized");
64
- const ColorinoBrowserObject = Symbol("colorino.browserObject");
65
-
66
- const catppuccinMochaPalette = {
67
- log: "#cdd6f4",
68
- // Text
69
- info: "#89b4fa",
70
- // Blue
71
- warn: "#f9e2af",
72
- // Yellow
73
- error: "#f38ba8",
74
- // Red
75
- debug: "#a6adc8",
76
- // Subtext0
77
- trace: "#9399b2"
78
- // Subtext1
79
- };
80
- const catppuccinLattePalette = {
81
- log: "#4c4f69",
82
- // Text
83
- info: "#1e66f5",
84
- // Blue
85
- warn: "#df8e1d",
86
- // Yellow
87
- error: "#d20f39",
88
- // Red
89
- debug: "#7c7f93",
90
- // Subtext0
91
- trace: "#8c8fa1"
92
- // Subtext1
93
- };
94
- const draculaPalette = {
95
- log: "#f8f8f2",
96
- // Foreground
97
- info: "#8be9fd",
98
- // Cyan
99
- warn: "#f1fa8c",
100
- // Yellow
101
- error: "#ff5555",
102
- // Red
103
- debug: "#bd93f9",
104
- // Purple
105
- trace: "#6272a4"
106
- // Comment
107
- };
108
- const githubLightPalette = {
109
- log: "#24292e",
110
- // Text
111
- info: "#0366d6",
112
- // Blue
113
- warn: "#f9a002",
114
- // Yellow
115
- error: "#d73a49",
116
- // Red
117
- debug: "#586069",
118
- // Gray
119
- trace: "#6a737d"
120
- // Gray-light
121
- };
122
-
123
- const themePalettes = {
124
- "catppuccin-mocha": catppuccinMochaPalette,
125
- "catppuccin-latte": catppuccinLattePalette,
126
- dracula: draculaPalette,
127
- "github-light": githubLightPalette
128
- };
129
- const defaultDarkTheme = "dracula";
130
- const defaultLightTheme = "github-light";
131
- function isThemeName(theme) {
132
- return theme in themePalettes;
133
- }
134
-
135
- function determineBaseTheme(themeOpt, detectedBrowserTheme) {
136
- let baseThemeName;
137
- if (isThemeName(themeOpt)) {
138
- baseThemeName = themeOpt;
139
- } else if (themeOpt === "light") {
140
- baseThemeName = defaultLightTheme;
141
- } else if (themeOpt === "dark") {
142
- baseThemeName = defaultDarkTheme;
143
- } else {
144
- baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
145
- }
146
- return baseThemeName;
147
- }
148
-
149
12
  class TypeValidator {
150
13
  static isNull(value) {
151
14
  return value === null;
152
15
  }
16
+ static isUndefined(value) {
17
+ return value === void 0;
18
+ }
19
+ static isNullOrUndefined(value) {
20
+ return value == null;
21
+ }
153
22
  static isObject(value) {
154
23
  return typeof value === "object" && value !== null;
155
24
  }
156
25
  static isString(value) {
157
- return typeof value === "string";
26
+ return typeof value === "string" || value instanceof String;
27
+ }
28
+ static isArray(value) {
29
+ return Array.isArray(value);
158
30
  }
159
31
  static isError(value) {
160
32
  return value instanceof Error;
161
33
  }
162
34
  static isBrowserColorizedArg(value) {
163
- return typeof value === "object" && value !== null && ColorinoBrowserColorized in value;
35
+ return TypeValidator.isObject(value) && ColorinoBrowserColorized in value;
164
36
  }
165
37
  static isBrowserObjectArg(value) {
166
- return typeof value === "object" && value !== null && ColorinoBrowserObject in value;
38
+ return TypeValidator.isObject(value) && ColorinoBrowserObject in value;
167
39
  }
168
40
  static isAnsiColoredString(value) {
169
- return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value);
41
+ return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value.toString());
170
42
  }
171
43
  static isFormattableObject(value) {
172
- return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value);
44
+ return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value) && !TypeValidator.isString(value);
45
+ }
46
+ static isConsoleMethod(level) {
47
+ return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
173
48
  }
174
49
  }
175
50
 
176
- class MyColorino {
177
- constructor(initialPalette, _userPalette, _validator, _browserColorSupportDetector, _nodeColorSupportDetector, _options = {}) {
51
+ class AbstractColorino {
52
+ constructor(initialPalette, _userPalette, _validator, colorLevel, _options = {}) {
178
53
  this._userPalette = _userPalette;
179
54
  this._validator = _validator;
180
- this._browserColorSupportDetector = _browserColorSupportDetector;
181
- this._nodeColorSupportDetector = _nodeColorSupportDetector;
182
55
  this._options = _options;
183
56
  this._palette = initialPalette;
184
- this.isBrowser = !!this._browserColorSupportDetector;
185
- this._colorLevel = this._detectColorSupport();
186
57
  const validatePaletteResult = this._validator.validatePalette(this._palette);
187
58
  if (validatePaletteResult.isErr()) throw validatePaletteResult.error;
188
- if (this._colorLevel !== ColorLevel.NO_COLOR && !this._options.disableWarnings && this._colorLevel === "UnknownEnv") {
189
- this._maybeWarnUser();
190
- }
191
- const themeOpt = this._options.theme ?? "auto";
192
- if (themeOpt === "auto" && this._nodeColorSupportDetector) {
193
- this._nodeColorSupportDetector.onTheme((resolvedTheme) => {
194
- this._applyResolvedTheme(resolvedTheme);
195
- });
196
- }
59
+ this._colorLevel = colorLevel;
197
60
  }
198
61
  _alreadyWarned = false;
199
62
  _colorLevel;
200
- isBrowser;
201
63
  _palette;
202
64
  log(...args) {
203
65
  this._out("log", args);
@@ -221,7 +83,7 @@ class MyColorino {
221
83
  if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
222
84
  return text;
223
85
  }
224
- if (this.isBrowser) {
86
+ if (this.isBrowser()) {
225
87
  return {
226
88
  [ColorinoBrowserColorized]: true,
227
89
  text,
@@ -234,99 +96,79 @@ class MyColorino {
234
96
  }
235
97
  return `${ansiPrefix}${text}\x1B[0m`;
236
98
  }
237
- _isAnsiColoredString(value) {
238
- return typeof value === "string" && /\x1b\[[0-9;]*m/.test(value);
239
- }
240
- _applyResolvedTheme(resolvedTheme) {
241
- const themeOpt = this._options.theme ?? "auto";
242
- const baseThemeName = determineBaseTheme(themeOpt, resolvedTheme);
243
- const basePalette = themePalettes[baseThemeName];
244
- this._palette = { ...basePalette, ...this._userPalette };
245
- }
246
- _detectColorSupport() {
247
- if (this.isBrowser) {
248
- return this._browserColorSupportDetector?.getColorLevel() ?? "UnknownEnv";
249
- }
250
- if (this._nodeColorSupportDetector?.isNodeEnv()) {
251
- return this._nodeColorSupportDetector?.getColorLevel() ?? "UnknownEnv";
99
+ _out(level, args) {
100
+ const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
101
+ const processedArgs = this.processArgs(args);
102
+ if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
103
+ this.output(consoleMethod, processedArgs);
104
+ return;
252
105
  }
253
- return "UnknownEnv";
106
+ const coloredArgs = this.applyColors(consoleMethod, processedArgs);
107
+ this.output(consoleMethod, coloredArgs);
254
108
  }
255
- _maybeWarnUser() {
256
- if (this._alreadyWarned) return;
257
- this._alreadyWarned = true;
258
- console.warn(
259
- "No ANSI color support detected in this terminal. See [https://github.com/chalk/supports-color#support-matrix](https://github.com/chalk/supports-color#support-matrix) to learn how to enable terminal color."
260
- );
109
+ _toAnsiPrefix(_hex) {
110
+ return "";
261
111
  }
262
112
  _formatValue(value, maxDepth = this._options.maxDepth ?? 5) {
263
113
  const seen = /* @__PURE__ */ new WeakSet();
114
+ const sanitizeArray = (items, depth) => {
115
+ return items.map((item) => sanitize(item, depth));
116
+ };
117
+ const sanitizeObject = (obj, depth) => {
118
+ const result = {};
119
+ for (const key in obj) {
120
+ result[key] = sanitize(obj[key], depth);
121
+ }
122
+ return result;
123
+ };
264
124
  const sanitize = (val, currentDepth) => {
265
- if (val == null || typeof val !== "object") return val;
125
+ if (TypeValidator.isNullOrUndefined(val) || !TypeValidator.isObject(val)) {
126
+ return val;
127
+ }
266
128
  if (seen.has(val)) return "[Circular]";
267
129
  seen.add(val);
268
130
  if (currentDepth >= maxDepth) return "[Object]";
269
- if (Array.isArray(val)) {
270
- return val.map((item) => sanitize(item, currentDepth + 1));
271
- }
272
- const result = {};
273
- for (const key in val) {
274
- result[key] = sanitize(
275
- val[key],
276
- currentDepth + 1
277
- );
131
+ const nextDepth = currentDepth + 1;
132
+ if (TypeValidator.isArray(val)) {
133
+ return sanitizeArray(val, nextDepth);
278
134
  }
279
- return result;
135
+ return sanitizeObject(val, nextDepth);
280
136
  };
281
137
  return JSON.stringify(sanitize(value, 0), null, 2);
282
138
  }
283
- _normalizeString(value) {
284
- if (value instanceof String) return value.valueOf();
285
- return value;
139
+ _filterStack(stack) {
140
+ return stack.split("\n").filter((line) => !line.match(/.*colorino.*/gi)).join("\n");
286
141
  }
287
- _processArgs(args) {
288
- const processedArgs = [];
289
- let previousWasObject = false;
290
- for (const rawArg of args) {
291
- const arg = this._normalizeString(rawArg);
292
- if (TypeValidator.isBrowserColorizedArg(arg)) {
293
- processedArgs.push(arg);
294
- previousWasObject = false;
295
- continue;
296
- }
297
- if (TypeValidator.isFormattableObject(arg)) {
298
- if (this.isBrowser) {
299
- processedArgs.push({
300
- [ColorinoBrowserObject]: true,
301
- value: arg
302
- });
303
- } else {
304
- processedArgs.push(`
305
- ${this._formatValue(arg)}`);
306
- }
307
- previousWasObject = true;
308
- } else if (TypeValidator.isError(arg)) {
309
- processedArgs.push("\n", this._cleanErrorStack(arg));
310
- previousWasObject = true;
311
- } else {
312
- if (TypeValidator.isString(arg) && previousWasObject) {
313
- processedArgs.push(`
314
- ${arg}`);
315
- } else {
316
- processedArgs.push(arg);
317
- }
318
- previousWasObject = false;
319
- }
142
+ _cleanErrorStack(error) {
143
+ if (!error.stack) return error;
144
+ const cleanStack = this._filterStack(error.stack);
145
+ const cloned = Object.create(Object.getPrototypeOf(error));
146
+ Object.assign(cloned, error);
147
+ cloned.stack = cleanStack;
148
+ return cloned;
149
+ }
150
+ _printCleanTrace(args) {
151
+ const error = new Error();
152
+ if (error.stack) {
153
+ const cleanStack = this._filterStack(error.stack);
154
+ console.log(...args, `
155
+ ${cleanStack}`);
156
+ } else {
157
+ console.log(...args);
320
158
  }
321
- return processedArgs;
322
159
  }
323
- _applyBrowserColors(consoleMethod, args) {
160
+ }
161
+
162
+ class ColorinoBrowser extends AbstractColorino {
163
+ constructor(initialPalette, userPalette, validator, colorLevel, options = {}) {
164
+ super(initialPalette, userPalette, validator, colorLevel, options);
165
+ }
166
+ applyColors(consoleMethod, args) {
324
167
  const formatParts = [];
325
168
  const cssArgs = [];
326
169
  const otherArgs = [];
327
170
  const paletteHex = this._palette[consoleMethod];
328
- for (const rawArg of args) {
329
- const arg = this._normalizeString(rawArg);
171
+ for (const arg of args) {
330
172
  if (TypeValidator.isBrowserColorizedArg(arg)) {
331
173
  formatParts.push(`%c${arg.text}`);
332
174
  cssArgs.push(`color:${arg.hex}`);
@@ -345,90 +187,83 @@ ${arg}`);
345
187
  formatParts.push("%o");
346
188
  otherArgs.push(arg);
347
189
  }
348
- if (formatParts.length === 0) {
349
- return args;
350
- }
190
+ if (formatParts.length === 0) return args;
351
191
  return [formatParts.join(""), ...cssArgs, ...otherArgs];
352
192
  }
353
- _toAnsiPrefix(hex) {
354
- if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
355
- return "";
356
- }
357
- switch (this._colorLevel) {
358
- case ColorLevel.TRUECOLOR: {
359
- const [r, g, b] = colorConverter.hex.toRgb(hex);
360
- return `\x1B[38;2;${r};${g};${b}m`;
361
- }
362
- case ColorLevel.ANSI256: {
363
- const code = colorConverter.hex.toAnsi256(hex);
364
- return `\x1B[38;5;${code}m`;
193
+ output(consoleMethod, args) {
194
+ console[consoleMethod](...args);
195
+ }
196
+ processArgs(args) {
197
+ const processedArgs = [];
198
+ let previousWasObject = false;
199
+ for (const arg of args) {
200
+ if (TypeValidator.isBrowserColorizedArg(arg)) {
201
+ processedArgs.push(arg);
202
+ previousWasObject = false;
203
+ continue;
365
204
  }
366
- case ColorLevel.ANSI:
367
- default: {
368
- const code = colorConverter.hex.toAnsi16(hex);
369
- return `\x1B[${code}m`;
205
+ if (TypeValidator.isFormattableObject(arg)) {
206
+ processedArgs.push({
207
+ [ColorinoBrowserObject]: true,
208
+ value: arg
209
+ });
210
+ previousWasObject = true;
211
+ } else if (TypeValidator.isError(arg)) {
212
+ processedArgs.push("\n", this._cleanErrorStack(arg));
213
+ previousWasObject = true;
214
+ } else {
215
+ processedArgs.push(
216
+ TypeValidator.isString(arg) && previousWasObject ? `
217
+ ${arg}` : arg
218
+ );
219
+ previousWasObject = false;
370
220
  }
371
221
  }
222
+ return processedArgs;
372
223
  }
373
- _applyNodeColors(consoleMethod, args) {
374
- const coloredArgs = [...args];
375
- const firstStringIndex = coloredArgs.findIndex(
376
- (arg) => typeof arg === "string"
377
- );
378
- if (firstStringIndex === -1) {
379
- return coloredArgs;
224
+ isBrowser() {
225
+ return true;
226
+ }
227
+ }
228
+
229
+ class BrowserColorSupportDetector {
230
+ constructor(_window, _navigator, _overrideTheme) {
231
+ this._window = _window;
232
+ this._navigator = _navigator;
233
+ this._overrideTheme = _overrideTheme;
234
+ }
235
+ isBrowserEnv() {
236
+ return !!this._window && !!this._navigator?.userAgent;
237
+ }
238
+ getColorLevel() {
239
+ const isTruecolor = window.matchMedia("(color-gamut: p3)").matches;
240
+ if (isTruecolor) {
241
+ return ColorLevel.TRUECOLOR;
380
242
  }
381
- const first = coloredArgs[firstStringIndex];
382
- if (this._isAnsiColoredString(first)) {
383
- return coloredArgs;
243
+ const isAnsi256 = window.matchMedia("(monochrome: 0)").matches;
244
+ if (isAnsi256) {
245
+ return ColorLevel.ANSI256;
384
246
  }
385
- const hex = this._palette[consoleMethod];
386
- const ansiPrefix = this._toAnsiPrefix(hex);
387
- if (!ansiPrefix) {
388
- return coloredArgs;
389
- }
390
- coloredArgs[firstStringIndex] = `${ansiPrefix}${String(first)}\x1B[0m`;
391
- return coloredArgs;
392
- }
393
- _output(consoleMethod, args) {
394
- if (consoleMethod === "trace") this._printCleanTrace(args);
395
- else console[consoleMethod](...args);
247
+ return ColorLevel.ANSI;
396
248
  }
397
- _out(level, args) {
398
- const consoleMethod = isConsoleMethod(level) ? level : "log";
399
- const processedArgs = this._processArgs(args);
400
- if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
401
- this._output(consoleMethod, processedArgs);
402
- return;
249
+ getTheme() {
250
+ if (this._overrideTheme) {
251
+ return this._overrideTheme;
403
252
  }
404
- if (this.isBrowser) {
405
- const coloredArgs2 = this._applyBrowserColors(consoleMethod, processedArgs);
406
- this._output(consoleMethod, coloredArgs2);
407
- return;
253
+ if (!this.isBrowserEnv() || typeof this._window.matchMedia !== "function") {
254
+ return "unknown";
408
255
  }
409
- const coloredArgs = this._applyNodeColors(consoleMethod, processedArgs);
410
- this._output(consoleMethod, coloredArgs);
411
- }
412
- _filterStack(stack) {
413
- return stack.split("\n").filter((line) => !line.match(/.*colorino.*/gi)).join("\n");
414
- }
415
- _cleanErrorStack(error) {
416
- if (!error.stack) return error;
417
- const cleanStack = this._filterStack(error.stack);
418
- const cloned = Object.create(Object.getPrototypeOf(error));
419
- Object.assign(cloned, error);
420
- cloned.stack = cleanStack;
421
- return cloned;
422
- }
423
- _printCleanTrace(args) {
424
- const error = new Error();
425
- if (error.stack) {
426
- const cleanStack = this._filterStack(error.stack);
427
- console.log(...args, `
428
- ${cleanStack}`);
429
- } else {
430
- console.log(...args);
256
+ const isDarkTheme = this._window.matchMedia(
257
+ "(prefers-color-scheme: dark)"
258
+ ).matches;
259
+ if (isDarkTheme) {
260
+ return "dark";
261
+ }
262
+ const isLightTheme = "(prefers-color-scheme: light)";
263
+ if (this._window.matchMedia(isLightTheme).matches) {
264
+ return "light";
431
265
  }
266
+ return "unknown";
432
267
  }
433
268
  }
434
269
 
@@ -943,4 +778,115 @@ class InputValidator {
943
778
  }
944
779
  }
945
780
 
946
- export { ColorLevel as C, InputValidator as I, MyColorino as M, determineBaseTheme as d, themePalettes as t };
781
+ const catppuccinMochaPalette = {
782
+ log: "#cdd6f4",
783
+ // Text
784
+ info: "#89b4fa",
785
+ // Blue
786
+ warn: "#f9e2af",
787
+ // Yellow
788
+ error: "#f38ba8",
789
+ // Red
790
+ debug: "#a6adc8",
791
+ // Subtext0
792
+ trace: "#9399b2"
793
+ // Subtext1
794
+ };
795
+ const catppuccinLattePalette = {
796
+ log: "#4c4f69",
797
+ // Text
798
+ info: "#1e66f5",
799
+ // Blue
800
+ warn: "#df8e1d",
801
+ // Yellow
802
+ error: "#d20f39",
803
+ // Red
804
+ debug: "#7c7f93",
805
+ // Subtext0
806
+ trace: "#8c8fa1"
807
+ // Subtext1
808
+ };
809
+ const draculaPalette = {
810
+ log: "#f8f8f2",
811
+ // Foreground
812
+ info: "#8be9fd",
813
+ // Cyan
814
+ warn: "#f1fa8c",
815
+ // Yellow
816
+ error: "#ff5555",
817
+ // Red
818
+ debug: "#bd93f9",
819
+ // Purple
820
+ trace: "#6272a4"
821
+ // Comment
822
+ };
823
+ const githubLightPalette = {
824
+ log: "#24292e",
825
+ // Text
826
+ info: "#0366d6",
827
+ // Blue
828
+ warn: "#f9a002",
829
+ // Yellow
830
+ error: "#d73a49",
831
+ // Red
832
+ debug: "#586069",
833
+ // Gray
834
+ trace: "#6a737d"
835
+ // Gray-light
836
+ };
837
+
838
+ const themePalettes = {
839
+ "catppuccin-mocha": catppuccinMochaPalette,
840
+ "catppuccin-latte": catppuccinLattePalette,
841
+ dracula: draculaPalette,
842
+ "github-light": githubLightPalette
843
+ };
844
+ const defaultDarkTheme = "dracula";
845
+ const defaultLightTheme = "github-light";
846
+ function isThemeName(theme) {
847
+ return theme in themePalettes;
848
+ }
849
+
850
+ function determineBaseTheme(themeOpt, detectedBrowserTheme) {
851
+ let baseThemeName;
852
+ if (isThemeName(themeOpt)) {
853
+ baseThemeName = themeOpt;
854
+ } else if (themeOpt === "light") {
855
+ baseThemeName = defaultLightTheme;
856
+ } else if (themeOpt === "dark") {
857
+ baseThemeName = defaultDarkTheme;
858
+ } else {
859
+ baseThemeName = detectedBrowserTheme === "light" ? defaultLightTheme : defaultDarkTheme;
860
+ }
861
+ return baseThemeName;
862
+ }
863
+
864
+ function createColorino(userPalette = {}, options = {}) {
865
+ const validator = new InputValidator();
866
+ let detectorThemeOverride;
867
+ if (options.theme === "dark" || options.theme === "light") {
868
+ detectorThemeOverride = options.theme;
869
+ }
870
+ const browserDetector = new BrowserColorSupportDetector(
871
+ window,
872
+ navigator,
873
+ detectorThemeOverride
874
+ );
875
+ const detectedBrowserTheme = browserDetector.getTheme();
876
+ const themeOpt = options.theme ?? "auto";
877
+ const baseThemeName = determineBaseTheme(themeOpt, detectedBrowserTheme);
878
+ const basePalette = themePalettes[baseThemeName];
879
+ const finalPalette = { ...basePalette, ...userPalette };
880
+ const colorLevel = browserDetector.isBrowserEnv() ? browserDetector.getColorLevel() ?? "UnknownEnv" : "UnknownEnv";
881
+ return new ColorinoBrowser(
882
+ finalPalette,
883
+ userPalette,
884
+ validator,
885
+ colorLevel,
886
+ options
887
+ );
888
+ }
889
+ const colorino = createColorino();
890
+
891
+ export { colorino, createColorino, themePalettes };
892
+ //# sourceMappingURL=cdn.mjs.map