@phun-ky/moebius 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +394 -5
- package/moebius.d.ts +4 -47
- package/moebius.js +1 -1
- package/moebius.js.map +1 -1
- package/package.json +31 -5
package/README.md
CHANGED
|
@@ -1,19 +1,44 @@
|
|
|
1
|
-
# @phun-ky/moebius
|
|
1
|
+
# @phun-ky/moebius `möbius`
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> Automatically generate color palettes!
|
|
6
6
|
|
|
7
7
|
[](http://commitizen.github.io/cz-cli/) [](http://makeapullrequest.com) [](http://semver.org/spec/v2.0.0.html)      
|
|
8
8
|
|
|
9
|
-
- [@phun-ky/moebius](#phun-kymoebius)
|
|
9
|
+
- [@phun-ky/moebius `möbius`](#phun-kymoebius-möbius)
|
|
10
10
|
- [About](#about)
|
|
11
|
+
- [Demo](#demo)
|
|
12
|
+
- [Install](#install)
|
|
11
13
|
- [API](#api)
|
|
12
14
|
- [Usage](#usage)
|
|
15
|
+
- [Creating paletts](#creating-paletts)
|
|
16
|
+
- [Interpolate](#interpolate)
|
|
17
|
+
- [Luminance shift](#luminance-shift)
|
|
18
|
+
- [Monochromatic](#monochromatic)
|
|
19
|
+
- [Complement](#complement)
|
|
20
|
+
- [Split](#split)
|
|
21
|
+
- [Triadic](#triadic)
|
|
22
|
+
- [Tetradic](#tetradic)
|
|
23
|
+
- [Pentadic](#pentadic)
|
|
24
|
+
- [Hexadic](#hexadic)
|
|
25
|
+
- [Analogous](#analogous)
|
|
26
|
+
- [Get color objects](#get-color-objects)
|
|
27
|
+
- [toString](#tostring)
|
|
28
|
+
- [toObject](#toobject)
|
|
29
|
+
- [toFloat](#tofloat)
|
|
30
|
+
- [Types](#types)
|
|
31
|
+
- [Sponsor me](#sponsor-me)
|
|
13
32
|
|
|
14
33
|
## About
|
|
15
34
|
|
|
16
|
-
|
|
35
|
+
@phun-ky/moebius (Möbius) was created to fit a need I had regarding color palette generation, and as a little challenge to myself. I was never happy with the current online palette generators, and I did not want a "set up" palette, I wanted something that was generated, ready to use, and something that I could use as inspiration on colors to choose from in my projects.
|
|
36
|
+
|
|
37
|
+
## Demo
|
|
38
|
+
|
|
39
|
+
You can check out a working codepen where you can [adjust settings and colors here](https://codepen.io/phun-ky/full/LYqQMqL).
|
|
40
|
+
|
|
41
|
+
## Install
|
|
17
42
|
|
|
18
43
|
```shell-session
|
|
19
44
|
npm i -S @phun-ky/moebius
|
|
@@ -24,3 +49,367 @@ npm i -S @phun-ky/moebius
|
|
|
24
49
|
Go [here](https://github.com/phun-ky/moebius/blob/main/api/README.md) to read the full API documentation.
|
|
25
50
|
|
|
26
51
|
## Usage
|
|
52
|
+
|
|
53
|
+
Import and run the required function:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import Moebius from '@phun-ky/moebius';
|
|
57
|
+
|
|
58
|
+
const { MoebiusColor, MoebiusPalettes } = await Moebius();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Creating paletts
|
|
62
|
+
|
|
63
|
+
The main feature is the ability to create palettes with a given primary color and a secondary color (used for diverging palettes). You can also give the color to diverge to/from.
|
|
64
|
+
|
|
65
|
+
**Default options**
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const defaultOptions = {
|
|
69
|
+
diverging: false,
|
|
70
|
+
bezier: false,
|
|
71
|
+
randomOffset: false,
|
|
72
|
+
correctLightness: false,
|
|
73
|
+
noDuplicates: true,
|
|
74
|
+
colorScaleMode: 'lch',
|
|
75
|
+
reverseDirection: false,
|
|
76
|
+
divergentColor: '#f5f5f5',
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
You initiate `MoebiusPalette` like this:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import Moebius from '@phun-ky/moebius';
|
|
84
|
+
|
|
85
|
+
const { MoebiusPalette, MoebiusColor } = await Moebius();
|
|
86
|
+
|
|
87
|
+
const palettes = new MoebiusPalettes({
|
|
88
|
+
baseColor: new MoebiusColor('#003f5c'),
|
|
89
|
+
secondaryColor: new MoebiusColor('#ff9900'),
|
|
90
|
+
...options,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
And then you can enjoy your palettes!
|
|
95
|
+
|
|
96
|
+
#### Interpolate
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
console.log(palettes.colors.interpolate);
|
|
100
|
+
/*
|
|
101
|
+
[
|
|
102
|
+
"#003f5c",
|
|
103
|
+
"#2b4e4d",
|
|
104
|
+
"#555d3d",
|
|
105
|
+
"#806c2e",
|
|
106
|
+
"#aa7b1f",
|
|
107
|
+
"#d58a0f",
|
|
108
|
+
"#ff9900"
|
|
109
|
+
]
|
|
110
|
+
*/
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Gives you an array of hex-colors.
|
|
114
|
+
|
|
115
|
+

|
|
116
|
+
|
|
117
|
+
#### Luminance shift
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
console.log(palettes.colors.luminanceShift);
|
|
121
|
+
/*
|
|
122
|
+
[
|
|
123
|
+
"#003f5c",
|
|
124
|
+
"#5f8bac",
|
|
125
|
+
"#b3dff2",
|
|
126
|
+
"#f5f5f5",
|
|
127
|
+
"#fcb852",
|
|
128
|
+
"#d17300",
|
|
129
|
+
"#762800"
|
|
130
|
+
]
|
|
131
|
+
*/
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Gives you an array of hex-colors.
|
|
135
|
+

|
|
136
|
+
|
|
137
|
+
If you diverge them, it could look like this:
|
|
138
|
+

|
|
139
|
+
|
|
140
|
+
#### Monochromatic
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
console.log(palettes.colors.monochromatic);
|
|
144
|
+
/*
|
|
145
|
+
[
|
|
146
|
+
"#003f5c",
|
|
147
|
+
"#003342",
|
|
148
|
+
"#002329",
|
|
149
|
+
"#000e0f",
|
|
150
|
+
"#000000"
|
|
151
|
+
]
|
|
152
|
+
*/
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Gives you an array of hex-colors.
|
|
156
|
+

|
|
157
|
+
|
|
158
|
+
#### Complement
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
console.log(palettes.colors.complement);
|
|
162
|
+
/*
|
|
163
|
+
[
|
|
164
|
+
"#003f5c",
|
|
165
|
+
"#0f394d",
|
|
166
|
+
"#1f343d",
|
|
167
|
+
"#2e2e2e",
|
|
168
|
+
"#3d281f",
|
|
169
|
+
"#4d230f",
|
|
170
|
+
"#5c1d00"
|
|
171
|
+
]
|
|
172
|
+
*/
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Gives you an array of hex-colors.
|
|
176
|
+

|
|
177
|
+
|
|
178
|
+
#### Split
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
console.log(palettes.colors.split);
|
|
182
|
+
/*
|
|
183
|
+
[
|
|
184
|
+
"#003f5c",
|
|
185
|
+
"#1f2a43",
|
|
186
|
+
"#3d152a",
|
|
187
|
+
"#5c0011",
|
|
188
|
+
"#5c190b",
|
|
189
|
+
"#5c3206",
|
|
190
|
+
"#5c4b00"
|
|
191
|
+
]
|
|
192
|
+
*/
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Gives you an array of hex-colors.
|
|
196
|
+

|
|
197
|
+
|
|
198
|
+
#### Triadic
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
console.log(palettes.colors.triadic);
|
|
202
|
+
/*
|
|
203
|
+
[
|
|
204
|
+
"#003f5c",
|
|
205
|
+
"#1f2a52",
|
|
206
|
+
"#3d1549",
|
|
207
|
+
"#5c003f",
|
|
208
|
+
"#521f2a",
|
|
209
|
+
"#493d15",
|
|
210
|
+
"#3f5c00"
|
|
211
|
+
]
|
|
212
|
+
*/
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Gives you an array of hex-colors.
|
|
216
|
+

|
|
217
|
+
|
|
218
|
+
#### Tetradic
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
console.log(palettes.colors.tetradic);
|
|
222
|
+
/*
|
|
223
|
+
[
|
|
224
|
+
"#003f5c",
|
|
225
|
+
"#26205c",
|
|
226
|
+
"#4b005c",
|
|
227
|
+
"#540f2e",
|
|
228
|
+
"#5c1d00",
|
|
229
|
+
"#363d00",
|
|
230
|
+
"#115c00"
|
|
231
|
+
]
|
|
232
|
+
*/
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Gives you an array of hex-colors.
|
|
236
|
+

|
|
237
|
+
|
|
238
|
+
#### Pentadic
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
console.log(palettes.colors.pentadic);
|
|
242
|
+
/*
|
|
243
|
+
[
|
|
244
|
+
"#003f5c",
|
|
245
|
+
"#2e203b",
|
|
246
|
+
"#5c001a",
|
|
247
|
+
"#5c2a0d",
|
|
248
|
+
"#5c5400",
|
|
249
|
+
"#2e5806",
|
|
250
|
+
"#005c0b"
|
|
251
|
+
]
|
|
252
|
+
*/
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Gives you an array of hex-colors.
|
|
256
|
+

|
|
257
|
+
|
|
258
|
+
#### Hexadic
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
console.log(palettes.colors.hexadic);
|
|
262
|
+
/*
|
|
263
|
+
[
|
|
264
|
+
"#003f5c",
|
|
265
|
+
"#3d1549",
|
|
266
|
+
"#5c0a2a",
|
|
267
|
+
"#5c1d00",
|
|
268
|
+
"#494700",
|
|
269
|
+
"#2a5c0a",
|
|
270
|
+
"#005c1d"
|
|
271
|
+
]
|
|
272
|
+
*/
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Gives you an array of hex-colors.
|
|
276
|
+

|
|
277
|
+
|
|
278
|
+
#### Analogous
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
console.log(palettes.colors.interpolate);
|
|
282
|
+
/*
|
|
283
|
+
[
|
|
284
|
+
"#003f5c",
|
|
285
|
+
"#00285c",
|
|
286
|
+
"#00115c",
|
|
287
|
+
"#0f085c",
|
|
288
|
+
"#1d005c",
|
|
289
|
+
"#34005c",
|
|
290
|
+
"#4b005c"
|
|
291
|
+
]
|
|
292
|
+
*/
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Gives you an array of hex-colors.
|
|
296
|
+

|
|
297
|
+
|
|
298
|
+
### Get color objects
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
import Moebius from '@phun-ky/moebius';
|
|
302
|
+
|
|
303
|
+
const { MoebiusColor } = await Moebius();
|
|
304
|
+
|
|
305
|
+
//
|
|
306
|
+
const color = new MoebiusColor('#003f5c');
|
|
307
|
+
|
|
308
|
+
console.log(color.hsl); // hsl(199, 100%, 18%);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
This will make available a color object with all of the colors readily converted and ready to use. This is an example output of the color object:
|
|
312
|
+
|
|
313
|
+
```json
|
|
314
|
+
{
|
|
315
|
+
"color": "#003f5c",
|
|
316
|
+
"name": "Maniac Mansion",
|
|
317
|
+
"hex": "#003f5c",
|
|
318
|
+
"rgb": "rgb(0, 63, 92)",
|
|
319
|
+
"hsl": {
|
|
320
|
+
"h": 199,
|
|
321
|
+
"s": 100,
|
|
322
|
+
"l": 18
|
|
323
|
+
},
|
|
324
|
+
"hwb": {
|
|
325
|
+
"h": 0.45,
|
|
326
|
+
"w": 0,
|
|
327
|
+
"b": 0.64
|
|
328
|
+
},
|
|
329
|
+
"hsv": {
|
|
330
|
+
"h": 198.91,
|
|
331
|
+
"s": 1,
|
|
332
|
+
"v": 0.36
|
|
333
|
+
},
|
|
334
|
+
"lab": {
|
|
335
|
+
"l": 24.72,
|
|
336
|
+
"a": -5.95,
|
|
337
|
+
"b": -22.26
|
|
338
|
+
},
|
|
339
|
+
"xyz": {
|
|
340
|
+
"x": 0.37,
|
|
341
|
+
"y": 0.43,
|
|
342
|
+
"z": 0.38
|
|
343
|
+
},
|
|
344
|
+
"lch": {
|
|
345
|
+
"l": 24.72,
|
|
346
|
+
"c": 23.04,
|
|
347
|
+
"h": 255.03
|
|
348
|
+
},
|
|
349
|
+
"oklch": {
|
|
350
|
+
"l": 0.35,
|
|
351
|
+
"c": 0.08,
|
|
352
|
+
"h": 236.65
|
|
353
|
+
},
|
|
354
|
+
"hsi": {
|
|
355
|
+
"h": 197.96,
|
|
356
|
+
"s": 1,
|
|
357
|
+
"i": 0.2
|
|
358
|
+
},
|
|
359
|
+
"oklab": {
|
|
360
|
+
"l": 0.35,
|
|
361
|
+
"a": -0.04,
|
|
362
|
+
"b": -0.06
|
|
363
|
+
},
|
|
364
|
+
"cmyk": {
|
|
365
|
+
"c": 100,
|
|
366
|
+
"m": 0,
|
|
367
|
+
"y": 32,
|
|
368
|
+
"k": 64
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
#### toString
|
|
374
|
+
|
|
375
|
+
For the non-CSS units, the color object also exposes a `toString` method pr unit:
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
const color = new MoebiusColor('#003f5c');
|
|
379
|
+
|
|
380
|
+
console.log(color.hsl.toString()); // "199, 100, 18"
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
#### toObject
|
|
384
|
+
|
|
385
|
+
The color object exposes a `toObject` method, that allows to objectify from any color unit given to either a color object for the hsl units, or default rgb:
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
const color = new MoebiusColor('#003f5c');
|
|
389
|
+
|
|
390
|
+
console.log(color.toObject('hsl')); // "199, 100, 18"
|
|
391
|
+
console.log(color.toObject(); // "0, 63, 92"
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
#### toFloat
|
|
395
|
+
|
|
396
|
+
The color object exposes a `toFloat` method, that allows to objectify to float values, as in `0-1` instead of `0-255`/`0-100` from any color unit given to either a color object for the hsl units, or default rgb:
|
|
397
|
+
|
|
398
|
+
```ts
|
|
399
|
+
const color = new MoebiusColor('#003f5c');
|
|
400
|
+
|
|
401
|
+
console.log(color.toFloat('hsl')); // "199, 1, 0.18"
|
|
402
|
+
console.log(color.toFloat(); // "0, 0.25, 0.36"
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Types
|
|
406
|
+
|
|
407
|
+
Types can be found in `@phun-ky/moebius/moebius.d.ts`.
|
|
408
|
+
|
|
409
|
+
## Sponsor me
|
|
410
|
+
|
|
411
|
+
I'm an Open Source evangelist, creating stuff that does not exist yet to help get rid of secondary activities and to enhance systems already in place, be it documentation or web sites.
|
|
412
|
+
|
|
413
|
+
The sponsorship is an unique opportunity to alleviate more hours for me to maintain my projects, create new ones and contribute to the large community we're all part of :)
|
|
414
|
+
|
|
415
|
+
[Support me with GitHub Sponsors](https://github.com/sponsors/phun-ky).
|
package/moebius.d.ts
CHANGED
|
@@ -431,7 +431,7 @@ declare class MoebiusPalettes implements MoebiusPaletteInterface {
|
|
|
431
431
|
* ```
|
|
432
432
|
*/
|
|
433
433
|
declare class MoebiusColor implements MoebiusColorInterface {
|
|
434
|
-
color:
|
|
434
|
+
color: MoebiusChromaColorInputType;
|
|
435
435
|
name: string;
|
|
436
436
|
hex: MoebiusColorValueHexType;
|
|
437
437
|
rgb: MoebiusColorValueRgbType;
|
|
@@ -447,12 +447,12 @@ declare class MoebiusColor implements MoebiusColorInterface {
|
|
|
447
447
|
cmyk: MoebiusCMYKObjectType;
|
|
448
448
|
/**
|
|
449
449
|
* Creates an instance of MoebiusColor.
|
|
450
|
-
* @param {
|
|
450
|
+
* @param {MoebiusChromaColorInputType} value - The hex value of the color.
|
|
451
451
|
* @param {string} name - The name of the color
|
|
452
452
|
* @constructor
|
|
453
453
|
* @throws Will throw an error if init has not been run before creating an instance.
|
|
454
454
|
*/
|
|
455
|
-
constructor(color:
|
|
455
|
+
constructor(color: MoebiusChromaColorInputType, name: string);
|
|
456
456
|
/**
|
|
457
457
|
* Converts the color to an object in the specified color space.
|
|
458
458
|
* @param {string} type - The color space type (e.g., 'rgb' or 'hsl').
|
|
@@ -467,53 +467,10 @@ declare class MoebiusColor implements MoebiusColorInterface {
|
|
|
467
467
|
toFloat(type?: string): MoebiusRGBObjectType | MoebiusHSLObjectType;
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
/**
|
|
471
|
-
* Class representing a set of accent colors in various palettes.
|
|
472
|
-
*/
|
|
473
|
-
declare class MoebiusAccentColors implements MoebiusPaletteAccentColorsInterface {
|
|
474
|
-
interpolate: MoebiusColorValueHexType[][];
|
|
475
|
-
luminanceShift: MoebiusColorValueHexType[][];
|
|
476
|
-
monochromatic: MoebiusColorValueHexType[][];
|
|
477
|
-
complement: MoebiusColorValueHexType[][];
|
|
478
|
-
split: MoebiusColorValueHexType[][];
|
|
479
|
-
triadic: MoebiusColorValueHexType[][];
|
|
480
|
-
tetradic: MoebiusColorValueHexType[][];
|
|
481
|
-
pentadic: MoebiusColorValueHexType[][];
|
|
482
|
-
hexadic: MoebiusColorValueHexType[][];
|
|
483
|
-
analogous: MoebiusColorValueHexType[][];
|
|
484
|
-
/**
|
|
485
|
-
* Creates an instance of MoebiusAccentColors.
|
|
486
|
-
* @param {MoebiusPaletteColorsInterface} colors - Base colors for accent palettes.
|
|
487
|
-
* @param {MoebiusPaletteOptionsType} options - Options for generating accent palettes.
|
|
488
|
-
* @example
|
|
489
|
-
* ```ts
|
|
490
|
-
* const colors = {
|
|
491
|
-
* monochromatic: ['#ff0000', '#00ff00'],
|
|
492
|
-
* // other base palettes...
|
|
493
|
-
* };
|
|
494
|
-
* const options = { baseColor: { color: '#ff0000', name: 'Red', hex: '#ff0000' }, numberOfColors: 9 };
|
|
495
|
-
* const accentColors = new MoebiusAccentColors(colors, options);
|
|
496
|
-
* ```
|
|
497
|
-
*/
|
|
498
|
-
constructor(colors: MoebiusPaletteColorsInterface, options: MoebiusPaletteOptionsType);
|
|
499
|
-
/**
|
|
500
|
-
* Converts the accent palettes to a flat array.
|
|
501
|
-
* @returns {MoebiusColorValueHexType[]} - Array of hex color values.
|
|
502
|
-
* @example
|
|
503
|
-
* ```ts
|
|
504
|
-
* const accentColors = new MoebiusAccentColors(baseColors, options);
|
|
505
|
-
* const flatArray = accentColors.toArray();
|
|
506
|
-
* console.log(flatArray); // ['#ff0000', '#00ff00', ...]
|
|
507
|
-
* ```
|
|
508
|
-
*/
|
|
509
|
-
toArray(): MoebiusColorValueHexType[];
|
|
510
|
-
}
|
|
511
|
-
|
|
512
470
|
type MoebiusReturnType = Promise<{
|
|
513
471
|
MoebiusColor: typeof MoebiusColor;
|
|
514
472
|
MoebiusPalettes: typeof MoebiusPalettes;
|
|
515
473
|
MoebiusSVGHelper: typeof MoebiusSVGHelper;
|
|
516
|
-
MoebiusAccentColors: typeof MoebiusAccentColors;
|
|
517
474
|
}>;
|
|
518
475
|
/**
|
|
519
476
|
* Asynchronous function to initialize Moebius with required data
|
|
@@ -523,4 +480,4 @@ type MoebiusReturnType = Promise<{
|
|
|
523
480
|
*/
|
|
524
481
|
declare function Moebius(): MoebiusReturnType;
|
|
525
482
|
|
|
526
|
-
export {
|
|
483
|
+
export { MoebiusReturnType, Moebius as default };
|