@flyingrobots/bijou 0.9.0 → 1.0.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.
- package/dist/adapters/test/assertions.d.ts +51 -0
- package/dist/adapters/test/assertions.d.ts.map +1 -0
- package/dist/adapters/test/assertions.js +67 -0
- package/dist/adapters/test/assertions.js.map +1 -0
- package/dist/adapters/test/audit-style.d.ts +28 -7
- package/dist/adapters/test/audit-style.d.ts.map +1 -1
- package/dist/adapters/test/audit-style.js +61 -4
- package/dist/adapters/test/audit-style.js.map +1 -1
- package/dist/adapters/test/index.d.ts +36 -1
- package/dist/adapters/test/index.d.ts.map +1 -1
- package/dist/adapters/test/index.js +12 -1
- package/dist/adapters/test/index.js.map +1 -1
- package/dist/adapters/test/io.d.ts +27 -0
- package/dist/adapters/test/io.d.ts.map +1 -1
- package/dist/adapters/test/io.js +56 -0
- package/dist/adapters/test/io.js.map +1 -1
- package/dist/adapters/test/runtime.d.ts +17 -0
- package/dist/adapters/test/runtime.d.ts.map +1 -1
- package/dist/adapters/test/runtime.js +14 -0
- package/dist/adapters/test/runtime.js.map +1 -1
- package/dist/adapters/test/style.d.ts +9 -0
- package/dist/adapters/test/style.d.ts.map +1 -1
- package/dist/adapters/test/style.js +54 -0
- package/dist/adapters/test/style.js.map +1 -1
- package/dist/context.d.ts +21 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +21 -0
- package/dist/context.js.map +1 -1
- package/dist/core/bg-fill.d.ts +32 -0
- package/dist/core/bg-fill.d.ts.map +1 -0
- package/dist/core/bg-fill.js +42 -0
- package/dist/core/bg-fill.js.map +1 -0
- package/dist/core/components/accordion.d.ts +20 -0
- package/dist/core/components/accordion.d.ts.map +1 -1
- package/dist/core/components/accordion.js +13 -6
- package/dist/core/components/accordion.js.map +1 -1
- package/dist/core/components/alert.d.ts +16 -0
- package/dist/core/components/alert.d.ts.map +1 -1
- package/dist/core/components/alert.js +17 -6
- package/dist/core/components/alert.js.map +1 -1
- package/dist/core/components/badge.d.ts +18 -0
- package/dist/core/components/badge.d.ts.map +1 -1
- package/dist/core/components/badge.js +15 -11
- package/dist/core/components/badge.js.map +1 -1
- package/dist/core/components/box.d.ts +33 -0
- package/dist/core/components/box.d.ts.map +1 -1
- package/dist/core/components/box.js +72 -23
- package/dist/core/components/box.js.map +1 -1
- package/dist/core/components/breadcrumb.d.ts +15 -0
- package/dist/core/components/breadcrumb.d.ts.map +1 -1
- package/dist/core/components/breadcrumb.js +13 -6
- package/dist/core/components/breadcrumb.js.map +1 -1
- package/dist/core/components/dag-source.d.ts +52 -9
- package/dist/core/components/dag-source.d.ts.map +1 -1
- package/dist/core/components/dag-source.js +53 -9
- package/dist/core/components/dag-source.js.map +1 -1
- package/dist/core/components/dag-stats.d.ts +2 -0
- package/dist/core/components/dag-stats.d.ts.map +1 -1
- package/dist/core/components/dag-stats.js.map +1 -1
- package/dist/core/components/dag.d.ts +88 -1
- package/dist/core/components/dag.d.ts.map +1 -1
- package/dist/core/components/dag.js +127 -6
- package/dist/core/components/dag.js.map +1 -1
- package/dist/core/components/enumerated-list.d.ts +30 -0
- package/dist/core/components/enumerated-list.d.ts.map +1 -1
- package/dist/core/components/enumerated-list.js +50 -11
- package/dist/core/components/enumerated-list.js.map +1 -1
- package/dist/core/components/hyperlink.d.ts +16 -0
- package/dist/core/components/hyperlink.d.ts.map +1 -1
- package/dist/core/components/hyperlink.js +22 -11
- package/dist/core/components/hyperlink.js.map +1 -1
- package/dist/core/components/index.d.ts +7 -0
- package/dist/core/components/index.d.ts.map +1 -1
- package/dist/core/components/index.js +7 -0
- package/dist/core/components/index.js.map +1 -1
- package/dist/core/components/kbd.d.ts +14 -0
- package/dist/core/components/kbd.d.ts.map +1 -1
- package/dist/core/components/kbd.js +13 -6
- package/dist/core/components/kbd.js.map +1 -1
- package/dist/core/components/log.d.ts +20 -0
- package/dist/core/components/log.d.ts.map +1 -1
- package/dist/core/components/log.js +24 -11
- package/dist/core/components/log.js.map +1 -1
- package/dist/core/components/logo.d.ts +32 -0
- package/dist/core/components/logo.d.ts.map +1 -1
- package/dist/core/components/logo.js +38 -0
- package/dist/core/components/logo.js.map +1 -1
- package/dist/core/components/markdown.d.ts +7 -1
- package/dist/core/components/markdown.d.ts.map +1 -1
- package/dist/core/components/markdown.js +76 -0
- package/dist/core/components/markdown.js.map +1 -1
- package/dist/core/components/paginator.d.ts +16 -0
- package/dist/core/components/paginator.d.ts.map +1 -1
- package/dist/core/components/paginator.js +12 -6
- package/dist/core/components/paginator.js.map +1 -1
- package/dist/core/components/progress.d.ts +55 -0
- package/dist/core/components/progress.d.ts.map +1 -1
- package/dist/core/components/progress.js +37 -6
- package/dist/core/components/progress.js.map +1 -1
- package/dist/core/components/separator.d.ts +16 -0
- package/dist/core/components/separator.d.ts.map +1 -1
- package/dist/core/components/separator.js +12 -6
- package/dist/core/components/separator.js.map +1 -1
- package/dist/core/components/skeleton.d.ts +15 -0
- package/dist/core/components/skeleton.d.ts.map +1 -1
- package/dist/core/components/skeleton.js +12 -6
- package/dist/core/components/skeleton.js.map +1 -1
- package/dist/core/components/spinner.d.ts +37 -0
- package/dist/core/components/spinner.d.ts.map +1 -1
- package/dist/core/components/spinner.js +26 -6
- package/dist/core/components/spinner.js.map +1 -1
- package/dist/core/components/stepper.d.ts +20 -0
- package/dist/core/components/stepper.d.ts.map +1 -1
- package/dist/core/components/stepper.js +16 -6
- package/dist/core/components/stepper.js.map +1 -1
- package/dist/core/components/table.d.ts +20 -0
- package/dist/core/components/table.d.ts.map +1 -1
- package/dist/core/components/table.js +31 -6
- package/dist/core/components/table.js.map +1 -1
- package/dist/core/components/tabs.d.ts +19 -0
- package/dist/core/components/tabs.d.ts.map +1 -1
- package/dist/core/components/tabs.js +19 -6
- package/dist/core/components/tabs.js.map +1 -1
- package/dist/core/components/timeline.d.ts +19 -0
- package/dist/core/components/timeline.d.ts.map +1 -1
- package/dist/core/components/timeline.js +20 -6
- package/dist/core/components/timeline.js.map +1 -1
- package/dist/core/components/tree.d.ts +19 -0
- package/dist/core/components/tree.d.ts.map +1 -1
- package/dist/core/components/tree.js +49 -11
- package/dist/core/components/tree.js.map +1 -1
- package/dist/core/detect/index.d.ts +8 -2
- package/dist/core/detect/index.d.ts.map +1 -1
- package/dist/core/detect/index.js +7 -1
- package/dist/core/detect/index.js.map +1 -1
- package/dist/core/detect/tty.d.ts +36 -0
- package/dist/core/detect/tty.d.ts.map +1 -1
- package/dist/core/detect/tty.js +34 -0
- package/dist/core/detect/tty.js.map +1 -1
- package/dist/core/forms/confirm.d.ts +14 -0
- package/dist/core/forms/confirm.d.ts.map +1 -1
- package/dist/core/forms/confirm.js +15 -5
- package/dist/core/forms/confirm.js.map +1 -1
- package/dist/core/forms/filter.d.ts +30 -0
- package/dist/core/forms/filter.d.ts.map +1 -1
- package/dist/core/forms/filter.js +67 -49
- package/dist/core/forms/filter.js.map +1 -1
- package/dist/core/forms/form-utils.d.ts +103 -0
- package/dist/core/forms/form-utils.d.ts.map +1 -0
- package/dist/core/forms/form-utils.js +135 -0
- package/dist/core/forms/form-utils.js.map +1 -0
- package/dist/core/forms/group.d.ts +12 -0
- package/dist/core/forms/group.d.ts.map +1 -1
- package/dist/core/forms/group.js +7 -0
- package/dist/core/forms/group.js.map +1 -1
- package/dist/core/forms/index.d.ts +6 -0
- package/dist/core/forms/index.d.ts.map +1 -1
- package/dist/core/forms/index.js +6 -0
- package/dist/core/forms/index.js.map +1 -1
- package/dist/core/forms/input.d.ts +17 -0
- package/dist/core/forms/input.d.ts.map +1 -1
- package/dist/core/forms/input.js +27 -15
- package/dist/core/forms/input.js.map +1 -1
- package/dist/core/forms/multiselect.d.ts +16 -0
- package/dist/core/forms/multiselect.d.ts.map +1 -1
- package/dist/core/forms/multiselect.js +54 -38
- package/dist/core/forms/multiselect.js.map +1 -1
- package/dist/core/forms/select.d.ts +17 -0
- package/dist/core/forms/select.d.ts.map +1 -1
- package/dist/core/forms/select.js +51 -37
- package/dist/core/forms/select.js.map +1 -1
- package/dist/core/forms/textarea.d.ts +19 -0
- package/dist/core/forms/textarea.d.ts.map +1 -1
- package/dist/core/forms/textarea.js +51 -47
- package/dist/core/forms/textarea.js.map +1 -1
- package/dist/core/forms/types.d.ts +41 -2
- package/dist/core/forms/types.d.ts.map +1 -1
- package/dist/core/forms/wizard.d.ts +19 -0
- package/dist/core/forms/wizard.d.ts.map +1 -1
- package/dist/core/forms/wizard.js +4 -0
- package/dist/core/forms/wizard.js.map +1 -1
- package/dist/core/resolve-ctx.d.ts +30 -0
- package/dist/core/resolve-ctx.d.ts.map +1 -0
- package/dist/core/resolve-ctx.js +43 -0
- package/dist/core/resolve-ctx.js.map +1 -0
- package/dist/core/text/clip.d.ts +21 -0
- package/dist/core/text/clip.d.ts.map +1 -0
- package/dist/core/text/clip.js +75 -0
- package/dist/core/text/clip.js.map +1 -0
- package/dist/core/text/grapheme.d.ts +15 -3
- package/dist/core/text/grapheme.d.ts.map +1 -1
- package/dist/core/text/grapheme.js +21 -3
- package/dist/core/text/grapheme.js.map +1 -1
- package/dist/core/text/index.d.ts +8 -0
- package/dist/core/text/index.d.ts.map +1 -1
- package/dist/core/text/index.js +8 -0
- package/dist/core/text/index.js.map +1 -1
- package/dist/core/theme/color.d.ts +47 -8
- package/dist/core/theme/color.d.ts.map +1 -1
- package/dist/core/theme/color.js +77 -8
- package/dist/core/theme/color.js.map +1 -1
- package/dist/core/theme/downsample.d.ts +24 -6
- package/dist/core/theme/downsample.d.ts.map +1 -1
- package/dist/core/theme/downsample.js +41 -10
- package/dist/core/theme/downsample.js.map +1 -1
- package/dist/core/theme/dtcg.d.ts +28 -2
- package/dist/core/theme/dtcg.d.ts.map +1 -1
- package/dist/core/theme/dtcg.js +112 -9
- package/dist/core/theme/dtcg.js.map +1 -1
- package/dist/core/theme/extend.d.ts +14 -0
- package/dist/core/theme/extend.d.ts.map +1 -1
- package/dist/core/theme/extend.js +14 -0
- package/dist/core/theme/extend.js.map +1 -1
- package/dist/core/theme/gradient.d.ts +16 -0
- package/dist/core/theme/gradient.d.ts.map +1 -1
- package/dist/core/theme/gradient.js +13 -0
- package/dist/core/theme/gradient.js.map +1 -1
- package/dist/core/theme/index.d.ts +7 -0
- package/dist/core/theme/index.d.ts.map +1 -1
- package/dist/core/theme/index.js +7 -0
- package/dist/core/theme/index.js.map +1 -1
- package/dist/core/theme/presets.d.ts +6 -1
- package/dist/core/theme/presets.d.ts.map +1 -1
- package/dist/core/theme/presets.js +34 -1
- package/dist/core/theme/presets.js.map +1 -1
- package/dist/core/theme/resolve.d.ts +59 -13
- package/dist/core/theme/resolve.d.ts.map +1 -1
- package/dist/core/theme/resolve.js +36 -9
- package/dist/core/theme/resolve.js.map +1 -1
- package/dist/core/theme/styled.d.ts +12 -0
- package/dist/core/theme/styled.d.ts.map +1 -1
- package/dist/core/theme/styled.js +12 -0
- package/dist/core/theme/styled.js.map +1 -1
- package/dist/core/theme/tokens.d.ts +29 -0
- package/dist/core/theme/tokens.d.ts.map +1 -1
- package/dist/factory.d.ts +18 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +11 -0
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/ports/context.d.ts +11 -0
- package/dist/ports/context.d.ts.map +1 -1
- package/dist/ports/index.d.ts +6 -1
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +5 -0
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/io.d.ts +66 -2
- package/dist/ports/io.d.ts.map +1 -1
- package/dist/ports/runtime.d.ts +11 -0
- package/dist/ports/runtime.d.ts.map +1 -1
- package/dist/ports/style.d.ts +14 -0
- package/dist/ports/style.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,13 @@
|
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
// Segmenter (lazy singleton)
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
|
+
/** Cached singleton `Intl.Segmenter` instance for grapheme-level segmentation. */
|
|
10
11
|
let _segmenter;
|
|
12
|
+
/**
|
|
13
|
+
* Return the lazily-initialized grapheme segmenter singleton.
|
|
14
|
+
*
|
|
15
|
+
* @returns The shared `Intl.Segmenter` configured for English grapheme granularity.
|
|
16
|
+
*/
|
|
11
17
|
function segmenter() {
|
|
12
18
|
if (!_segmenter) {
|
|
13
19
|
_segmenter = new Intl.Segmenter('en', { granularity: 'grapheme' });
|
|
@@ -18,7 +24,7 @@ function segmenter() {
|
|
|
18
24
|
// Wide character detection
|
|
19
25
|
// ---------------------------------------------------------------------------
|
|
20
26
|
/**
|
|
21
|
-
*
|
|
27
|
+
* Determine whether a Unicode code point occupies two terminal columns.
|
|
22
28
|
*
|
|
23
29
|
* Covers:
|
|
24
30
|
* - CJK Unified Ideographs (U+4E00–U+9FFF)
|
|
@@ -32,6 +38,9 @@ function segmenter() {
|
|
|
32
38
|
* - CJK Compatibility (U+FE30–U+FE4F)
|
|
33
39
|
* - Hangul Syllables (U+AC00–U+D7A3)
|
|
34
40
|
* - Emoji (most U+1F000+)
|
|
41
|
+
*
|
|
42
|
+
* @param cp - Unicode code point to test.
|
|
43
|
+
* @returns `true` if the code point renders as two columns wide.
|
|
35
44
|
*/
|
|
36
45
|
export function isWideChar(cp) {
|
|
37
46
|
// Fullwidth Forms
|
|
@@ -98,6 +107,9 @@ export function isWideChar(cp) {
|
|
|
98
107
|
*
|
|
99
108
|
* Each element is a single user-perceived character (handles combining
|
|
100
109
|
* marks, ZWJ sequences, flag pairs, skin tones, etc.).
|
|
110
|
+
*
|
|
111
|
+
* @param str - Input string to segment.
|
|
112
|
+
* @returns Array of grapheme cluster strings.
|
|
101
113
|
*/
|
|
102
114
|
export function segmentGraphemes(str) {
|
|
103
115
|
const segments = segmenter().segment(str);
|
|
@@ -120,6 +132,9 @@ export function segmentGraphemes(str) {
|
|
|
120
132
|
*
|
|
121
133
|
* Zero-width characters (combining marks, ZWJ, variation selectors)
|
|
122
134
|
* don't add width on their own — they're part of the cluster.
|
|
135
|
+
*
|
|
136
|
+
* @param grapheme - A single grapheme cluster string.
|
|
137
|
+
* @returns Display width: 1 for narrow characters, 2 for wide/emoji.
|
|
123
138
|
*/
|
|
124
139
|
export function graphemeClusterWidth(grapheme) {
|
|
125
140
|
let maxWidth = 1;
|
|
@@ -139,12 +154,15 @@ export function graphemeClusterWidth(grapheme) {
|
|
|
139
154
|
/**
|
|
140
155
|
* Compute the terminal display width of a string.
|
|
141
156
|
*
|
|
142
|
-
*
|
|
143
|
-
* and
|
|
157
|
+
* Strip ANSI escape sequences, segment into grapheme clusters,
|
|
158
|
+
* and sum display widths. Correctly handles:
|
|
144
159
|
* - Multi-codepoint emoji (flags, ZWJ families, skin tones)
|
|
145
160
|
* - East Asian Wide characters (CJK, fullwidth forms)
|
|
146
161
|
* - Combining marks (accented characters)
|
|
147
162
|
* - ANSI escape sequences (ignored)
|
|
163
|
+
*
|
|
164
|
+
* @param str - Input string, may contain ANSI escape sequences.
|
|
165
|
+
* @returns Total display width in terminal columns.
|
|
148
166
|
*/
|
|
149
167
|
export function graphemeWidth(str) {
|
|
150
168
|
// Strip ANSI escapes first
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grapheme.js","sourceRoot":"","sources":["../../../src/core/text/grapheme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,6BAA6B;AAC7B,8EAA8E;AAE9E,IAAI,UAAsC,CAAC;AAE3C,SAAS,SAAS;IAChB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E
|
|
1
|
+
{"version":3,"file":"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
|
|
1
|
+
/**
|
|
2
|
+
* Text measurement and clipping utilities.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports grapheme-aware width calculation and ANSI-safe clipping
|
|
5
|
+
* from the `grapheme` and `clip` sub-modules.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
1
8
|
export { isWideChar, segmentGraphemes, graphemeClusterWidth, graphemeWidth, } from './grapheme.js';
|
|
9
|
+
export { clipToWidth } from './clip.js';
|
|
2
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/text/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/text/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/core/text/index.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text measurement and clipping utilities.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports grapheme-aware width calculation and ANSI-safe clipping
|
|
5
|
+
* from the `grapheme` and `clip` sub-modules.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
1
8
|
export { isWideChar, segmentGraphemes, graphemeClusterWidth, graphemeWidth, } from './grapheme.js';
|
|
9
|
+
export { clipToWidth } from './clip.js';
|
|
2
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/text/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/text/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -6,20 +6,59 @@
|
|
|
6
6
|
* preserve token modifiers.
|
|
7
7
|
*/
|
|
8
8
|
import type { RGB, TokenValue } from './tokens.js';
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Parse a hex color string to an RGB tuple. Supports `#RGB` and `#RRGGBB` (with or without `#`).
|
|
11
|
+
* @param hex - Hex color string to parse.
|
|
12
|
+
* @returns Parsed RGB tuple.
|
|
13
|
+
* @throws {Error} If the hex string is not a valid 3- or 6-digit hex color.
|
|
14
|
+
*/
|
|
10
15
|
export declare function hexToRgb(hex: string): RGB;
|
|
11
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Convert an RGB tuple to a `#rrggbb` hex string.
|
|
18
|
+
* @param rgb - RGB tuple to convert. Values are clamped to [0, 255].
|
|
19
|
+
* @returns Lowercase hex string with leading `#`.
|
|
20
|
+
*/
|
|
12
21
|
export declare function rgbToHex(rgb: RGB): string;
|
|
13
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Blend a token's color toward white by `amount` (0 = unchanged, 1 = white).
|
|
24
|
+
* @param token - Source token to lighten.
|
|
25
|
+
* @param amount - Blend factor, clamped to [0, 1].
|
|
26
|
+
* @returns New TokenValue with the lightened hex, preserving modifiers.
|
|
27
|
+
*/
|
|
14
28
|
export declare function lighten(token: TokenValue, amount: number): TokenValue;
|
|
15
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Blend a token's color toward black by `amount` (0 = unchanged, 1 = black).
|
|
31
|
+
* @param token - Source token to darken.
|
|
32
|
+
* @param amount - Blend factor, clamped to [0, 1].
|
|
33
|
+
* @returns New TokenValue with the darkened hex, preserving modifiers.
|
|
34
|
+
*/
|
|
16
35
|
export declare function darken(token: TokenValue, amount: number): TokenValue;
|
|
17
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Blend two token colors by `ratio` (0 = first, 1 = second, default 0.5). Preserves modifiers from the first token.
|
|
38
|
+
* @param a - First token (its modifiers are preserved).
|
|
39
|
+
* @param b - Second token.
|
|
40
|
+
* @param ratio - Blend ratio, clamped to [0, 1]. Default is 0.5.
|
|
41
|
+
* @returns New TokenValue with the blended hex.
|
|
42
|
+
*/
|
|
18
43
|
export declare function mix(a: TokenValue, b: TokenValue, ratio?: number): TokenValue;
|
|
19
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Rotate hue by 180 degrees to produce the complementary color.
|
|
46
|
+
* @param token - Source token.
|
|
47
|
+
* @returns New TokenValue with the complementary hex, preserving modifiers.
|
|
48
|
+
*/
|
|
20
49
|
export declare function complementary(token: TokenValue): TokenValue;
|
|
21
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Increase saturation by `amount` (0 = unchanged, 1 = full saturation).
|
|
52
|
+
* @param token - Source token.
|
|
53
|
+
* @param amount - Saturation increase factor, clamped to [0, 1].
|
|
54
|
+
* @returns New TokenValue with the saturated hex, preserving modifiers.
|
|
55
|
+
*/
|
|
22
56
|
export declare function saturate(token: TokenValue, amount: number): TokenValue;
|
|
23
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Decrease saturation by `amount` (0 = unchanged, 1 = fully desaturated).
|
|
59
|
+
* @param token - Source token.
|
|
60
|
+
* @param amount - Desaturation factor, clamped to [0, 1].
|
|
61
|
+
* @returns New TokenValue with the desaturated hex, preserving modifiers.
|
|
62
|
+
*/
|
|
24
63
|
export declare function desaturate(token: TokenValue, amount: number): TokenValue;
|
|
25
64
|
//# sourceMappingURL=color.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../src/core/theme/color.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAInD
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../src/core/theme/color.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAInD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAUzC;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAKzC;AAoGD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAQrE;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAQpE;AAED;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,KAAK,SAAM,GAAG,UAAU,CASzE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAK3D;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAMtE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAMxE"}
|
package/dist/core/theme/color.js
CHANGED
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
* preserve token modifiers.
|
|
7
7
|
*/
|
|
8
8
|
// ── Conversion ─────────────────────────────────────────────────────
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Parse a hex color string to an RGB tuple. Supports `#RGB` and `#RRGGBB` (with or without `#`).
|
|
11
|
+
* @param hex - Hex color string to parse.
|
|
12
|
+
* @returns Parsed RGB tuple.
|
|
13
|
+
* @throws {Error} If the hex string is not a valid 3- or 6-digit hex color.
|
|
14
|
+
*/
|
|
10
15
|
export function hexToRgb(hex) {
|
|
11
16
|
let h = hex.startsWith('#') ? hex.slice(1) : hex;
|
|
12
17
|
if (h.length === 3) {
|
|
@@ -18,7 +23,11 @@ export function hexToRgb(hex) {
|
|
|
18
23
|
const n = parseInt(h, 16);
|
|
19
24
|
return [(n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff];
|
|
20
25
|
}
|
|
21
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Convert an RGB tuple to a `#rrggbb` hex string.
|
|
28
|
+
* @param rgb - RGB tuple to convert. Values are clamped to [0, 255].
|
|
29
|
+
* @returns Lowercase hex string with leading `#`.
|
|
30
|
+
*/
|
|
22
31
|
export function rgbToHex(rgb) {
|
|
23
32
|
const r = Math.max(0, Math.min(255, Math.round(rgb[0])));
|
|
24
33
|
const g = Math.max(0, Math.min(255, Math.round(rgb[1])));
|
|
@@ -26,6 +35,11 @@ export function rgbToHex(rgb) {
|
|
|
26
35
|
return '#' + ((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1);
|
|
27
36
|
}
|
|
28
37
|
// ── Internal HSL helpers ───────────────────────────────────────────
|
|
38
|
+
/**
|
|
39
|
+
* Convert an RGB tuple to HSL (hue, saturation, lightness), all in [0, 1].
|
|
40
|
+
* @param rgb - Input RGB color.
|
|
41
|
+
* @returns HSL triple with each component normalized to [0, 1].
|
|
42
|
+
*/
|
|
29
43
|
function rgbToHsl(rgb) {
|
|
30
44
|
const r = rgb[0] / 255;
|
|
31
45
|
const g = rgb[1] / 255;
|
|
@@ -49,6 +63,13 @@ function rgbToHsl(rgb) {
|
|
|
49
63
|
}
|
|
50
64
|
return [h, s, l];
|
|
51
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Convert a single HSL hue sector to an RGB channel value.
|
|
68
|
+
* @param p - Lower bound from lightness calculation.
|
|
69
|
+
* @param q - Upper bound from lightness calculation.
|
|
70
|
+
* @param t - Hue offset for this channel.
|
|
71
|
+
* @returns Channel value in [0, 1].
|
|
72
|
+
*/
|
|
52
73
|
function hue2rgb(p, q, t) {
|
|
53
74
|
let tt = t;
|
|
54
75
|
if (tt < 0)
|
|
@@ -63,6 +84,13 @@ function hue2rgb(p, q, t) {
|
|
|
63
84
|
return p + (q - p) * (2 / 3 - tt) * 6;
|
|
64
85
|
return p;
|
|
65
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Convert HSL values to an RGB tuple.
|
|
89
|
+
* @param h - Hue in [0, 1].
|
|
90
|
+
* @param s - Saturation in [0, 1].
|
|
91
|
+
* @param l - Lightness in [0, 1].
|
|
92
|
+
* @returns RGB tuple with each channel in [0, 255].
|
|
93
|
+
*/
|
|
66
94
|
function hslToRgb(h, s, l) {
|
|
67
95
|
if (s === 0) {
|
|
68
96
|
const v = Math.round(l * 255);
|
|
@@ -77,16 +105,32 @@ function hslToRgb(h, s, l) {
|
|
|
77
105
|
];
|
|
78
106
|
}
|
|
79
107
|
// ── Token helpers ──────────────────────────────────────────────────
|
|
108
|
+
/**
|
|
109
|
+
* Clamp a numeric amount to the [0, 1] range.
|
|
110
|
+
* @param amount - Value to clamp.
|
|
111
|
+
* @returns Clamped value.
|
|
112
|
+
*/
|
|
80
113
|
function clampAmount(amount) {
|
|
81
114
|
return Math.max(0, Math.min(1, amount));
|
|
82
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Create a new TokenValue with the given hex, preserving the original's modifiers.
|
|
118
|
+
* @param token - Source token whose modifiers are carried over.
|
|
119
|
+
* @param hex - New hex color string.
|
|
120
|
+
* @returns New TokenValue with the updated hex.
|
|
121
|
+
*/
|
|
83
122
|
function withHex(token, hex) {
|
|
84
123
|
return token.modifiers
|
|
85
124
|
? { hex, modifiers: [...token.modifiers] }
|
|
86
125
|
: { hex };
|
|
87
126
|
}
|
|
88
127
|
// ── Manipulation ───────────────────────────────────────────────────
|
|
89
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Blend a token's color toward white by `amount` (0 = unchanged, 1 = white).
|
|
130
|
+
* @param token - Source token to lighten.
|
|
131
|
+
* @param amount - Blend factor, clamped to [0, 1].
|
|
132
|
+
* @returns New TokenValue with the lightened hex, preserving modifiers.
|
|
133
|
+
*/
|
|
90
134
|
export function lighten(token, amount) {
|
|
91
135
|
const t = clampAmount(amount);
|
|
92
136
|
const [r, g, b] = hexToRgb(token.hex);
|
|
@@ -96,7 +140,12 @@ export function lighten(token, amount) {
|
|
|
96
140
|
b + (255 - b) * t,
|
|
97
141
|
]));
|
|
98
142
|
}
|
|
99
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Blend a token's color toward black by `amount` (0 = unchanged, 1 = black).
|
|
145
|
+
* @param token - Source token to darken.
|
|
146
|
+
* @param amount - Blend factor, clamped to [0, 1].
|
|
147
|
+
* @returns New TokenValue with the darkened hex, preserving modifiers.
|
|
148
|
+
*/
|
|
100
149
|
export function darken(token, amount) {
|
|
101
150
|
const t = clampAmount(amount);
|
|
102
151
|
const [r, g, b] = hexToRgb(token.hex);
|
|
@@ -106,7 +155,13 @@ export function darken(token, amount) {
|
|
|
106
155
|
b * (1 - t),
|
|
107
156
|
]));
|
|
108
157
|
}
|
|
109
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Blend two token colors by `ratio` (0 = first, 1 = second, default 0.5). Preserves modifiers from the first token.
|
|
160
|
+
* @param a - First token (its modifiers are preserved).
|
|
161
|
+
* @param b - Second token.
|
|
162
|
+
* @param ratio - Blend ratio, clamped to [0, 1]. Default is 0.5.
|
|
163
|
+
* @returns New TokenValue with the blended hex.
|
|
164
|
+
*/
|
|
110
165
|
export function mix(a, b, ratio = 0.5) {
|
|
111
166
|
const t = clampAmount(ratio);
|
|
112
167
|
const [ar, ag, ab] = hexToRgb(a.hex);
|
|
@@ -117,14 +172,23 @@ export function mix(a, b, ratio = 0.5) {
|
|
|
117
172
|
ab + (bb - ab) * t,
|
|
118
173
|
]));
|
|
119
174
|
}
|
|
120
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* Rotate hue by 180 degrees to produce the complementary color.
|
|
177
|
+
* @param token - Source token.
|
|
178
|
+
* @returns New TokenValue with the complementary hex, preserving modifiers.
|
|
179
|
+
*/
|
|
121
180
|
export function complementary(token) {
|
|
122
181
|
const rgb = hexToRgb(token.hex);
|
|
123
182
|
const [h, s, l] = rgbToHsl(rgb);
|
|
124
183
|
const newH = (h + 0.5) % 1;
|
|
125
184
|
return withHex(token, rgbToHex(hslToRgb(newH, s, l)));
|
|
126
185
|
}
|
|
127
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* Increase saturation by `amount` (0 = unchanged, 1 = full saturation).
|
|
188
|
+
* @param token - Source token.
|
|
189
|
+
* @param amount - Saturation increase factor, clamped to [0, 1].
|
|
190
|
+
* @returns New TokenValue with the saturated hex, preserving modifiers.
|
|
191
|
+
*/
|
|
128
192
|
export function saturate(token, amount) {
|
|
129
193
|
const t = clampAmount(amount);
|
|
130
194
|
const rgb = hexToRgb(token.hex);
|
|
@@ -132,7 +196,12 @@ export function saturate(token, amount) {
|
|
|
132
196
|
const newS = Math.min(1, s + (1 - s) * t);
|
|
133
197
|
return withHex(token, rgbToHex(hslToRgb(h, newS, l)));
|
|
134
198
|
}
|
|
135
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Decrease saturation by `amount` (0 = unchanged, 1 = fully desaturated).
|
|
201
|
+
* @param token - Source token.
|
|
202
|
+
* @param amount - Desaturation factor, clamped to [0, 1].
|
|
203
|
+
* @returns New TokenValue with the desaturated hex, preserving modifiers.
|
|
204
|
+
*/
|
|
136
205
|
export function desaturate(token, amount) {
|
|
137
206
|
const t = clampAmount(amount);
|
|
138
207
|
const rgb = hexToRgb(token.hex);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/core/theme/color.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,sEAAsE;AAEtE
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/core/theme/color.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,sEAAsE;AAEtE;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACjD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;IACpD,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,GAAG,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1B,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAQ;IAC/B,MAAM,CAAC,GAAG,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C9B,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,MAAc;IAC1D,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACzB,OAAO,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -4,32 +4,50 @@
|
|
|
4
4
|
* Provides pure conversion functions for mapping RGB colors to lower
|
|
5
5
|
* color levels (ANSI 256, ANSI 16) without external dependencies.
|
|
6
6
|
*/
|
|
7
|
+
/** Terminal color capability level, from no color support to full 24-bit truecolor. */
|
|
7
8
|
export type ColorLevel = 'none' | 'ansi16' | 'ansi256' | 'truecolor';
|
|
8
9
|
/**
|
|
9
|
-
* Map an RGB color to the nearest ANSI 256 color index (16
|
|
10
|
+
* Map an RGB color to the nearest ANSI 256 color index (16-255).
|
|
10
11
|
*
|
|
11
12
|
* The ANSI 256 palette has:
|
|
12
|
-
* - Indices 0
|
|
13
|
-
* - Indices 16
|
|
14
|
-
* - Indices 232
|
|
13
|
+
* - Indices 0-15: standard + bright colors (not targeted here)
|
|
14
|
+
* - Indices 16-231: 6x6x6 color cube
|
|
15
|
+
* - Indices 232-255: grayscale ramp (24 shades)
|
|
16
|
+
*
|
|
17
|
+
* @param r - Red channel (0-255).
|
|
18
|
+
* @param g - Green channel (0-255).
|
|
19
|
+
* @param b - Blue channel (0-255).
|
|
20
|
+
* @returns ANSI 256 color index (16-255).
|
|
15
21
|
*/
|
|
16
22
|
export declare function rgbToAnsi256(r: number, g: number, b: number): number;
|
|
17
23
|
/**
|
|
18
24
|
* Find the nearest ANSI 256 color using Euclidean distance in RGB space.
|
|
19
25
|
*
|
|
20
|
-
* Considers both the
|
|
26
|
+
* Considers both the 6x6x6 cube and the grayscale ramp, returning
|
|
21
27
|
* whichever is closest to the input color.
|
|
28
|
+
*
|
|
29
|
+
* @param r - Red channel (0-255).
|
|
30
|
+
* @param g - Green channel (0-255).
|
|
31
|
+
* @param b - Blue channel (0-255).
|
|
32
|
+
* @returns ANSI 256 color index (16-255) closest to the input.
|
|
22
33
|
*/
|
|
23
34
|
export declare function nearestAnsi256(r: number, g: number, b: number): number;
|
|
24
35
|
/**
|
|
25
|
-
* Map an RGB color to the nearest ANSI 16 color index (0
|
|
36
|
+
* Map an RGB color to the nearest ANSI 16 color index (0-15).
|
|
26
37
|
*
|
|
27
38
|
* Uses Euclidean distance in RGB space to find the closest match
|
|
28
39
|
* among the 16 standard terminal colors.
|
|
40
|
+
*
|
|
41
|
+
* @param r - Red channel (0-255).
|
|
42
|
+
* @param g - Green channel (0-255).
|
|
43
|
+
* @param b - Blue channel (0-255).
|
|
44
|
+
* @returns ANSI 16 color index (0-15).
|
|
29
45
|
*/
|
|
30
46
|
export declare function rgbToAnsi16(r: number, g: number, b: number): number;
|
|
31
47
|
/**
|
|
32
48
|
* Convert an ANSI 256 color index to the nearest ANSI 16 color index.
|
|
49
|
+
* @param code - ANSI 256 color index (0-255).
|
|
50
|
+
* @returns ANSI 16 color index (0-15).
|
|
33
51
|
*/
|
|
34
52
|
export declare function ansi256ToAnsi16(code: number): number;
|
|
35
53
|
//# sourceMappingURL=downsample.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downsample.d.ts","sourceRoot":"","sources":["../../../src/core/theme/downsample.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;AAMrE
|
|
1
|
+
{"version":3,"file":"downsample.d.ts","sourceRoot":"","sources":["../../../src/core/theme/downsample.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uFAAuF;AACvF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;AAMrE;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAapE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA0BtE;AAmED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAcnE;AAMD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOpD"}
|
|
@@ -8,12 +8,17 @@
|
|
|
8
8
|
// RGB → ANSI 256
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
10
|
/**
|
|
11
|
-
* Map an RGB color to the nearest ANSI 256 color index (16
|
|
11
|
+
* Map an RGB color to the nearest ANSI 256 color index (16-255).
|
|
12
12
|
*
|
|
13
13
|
* The ANSI 256 palette has:
|
|
14
|
-
* - Indices 0
|
|
15
|
-
* - Indices 16
|
|
16
|
-
* - Indices 232
|
|
14
|
+
* - Indices 0-15: standard + bright colors (not targeted here)
|
|
15
|
+
* - Indices 16-231: 6x6x6 color cube
|
|
16
|
+
* - Indices 232-255: grayscale ramp (24 shades)
|
|
17
|
+
*
|
|
18
|
+
* @param r - Red channel (0-255).
|
|
19
|
+
* @param g - Green channel (0-255).
|
|
20
|
+
* @param b - Blue channel (0-255).
|
|
21
|
+
* @returns ANSI 256 color index (16-255).
|
|
17
22
|
*/
|
|
18
23
|
export function rgbToAnsi256(r, g, b) {
|
|
19
24
|
// Check if it's close to grayscale first
|
|
@@ -24,7 +29,7 @@ export function rgbToAnsi256(r, g, b) {
|
|
|
24
29
|
return 231; // white end of cube
|
|
25
30
|
return Math.round((r - 8) / 247 * 24) + 232;
|
|
26
31
|
}
|
|
27
|
-
// Map to
|
|
32
|
+
// Map to 6x6x6 color cube (indices 16-231)
|
|
28
33
|
const ri = Math.round(r / 255 * 5);
|
|
29
34
|
const gi = Math.round(g / 255 * 5);
|
|
30
35
|
const bi = Math.round(b / 255 * 5);
|
|
@@ -33,8 +38,13 @@ export function rgbToAnsi256(r, g, b) {
|
|
|
33
38
|
/**
|
|
34
39
|
* Find the nearest ANSI 256 color using Euclidean distance in RGB space.
|
|
35
40
|
*
|
|
36
|
-
* Considers both the
|
|
41
|
+
* Considers both the 6x6x6 cube and the grayscale ramp, returning
|
|
37
42
|
* whichever is closest to the input color.
|
|
43
|
+
*
|
|
44
|
+
* @param r - Red channel (0-255).
|
|
45
|
+
* @param g - Green channel (0-255).
|
|
46
|
+
* @param b - Blue channel (0-255).
|
|
47
|
+
* @returns ANSI 256 color index (16-255) closest to the input.
|
|
38
48
|
*/
|
|
39
49
|
export function nearestAnsi256(r, g, b) {
|
|
40
50
|
const cubeIdx = rgbToAnsi256(r, g, b);
|
|
@@ -61,7 +71,11 @@ export function nearestAnsi256(r, g, b) {
|
|
|
61
71
|
const grayDist = colorDistance(r, g, b, grayRgb[0], grayRgb[1], grayRgb[2]);
|
|
62
72
|
return grayDist < cubeDist ? grayIdx : cubeIdx;
|
|
63
73
|
}
|
|
64
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Convert an ANSI 256 index (16-255) back to approximate RGB.
|
|
76
|
+
* @param idx - ANSI 256 color index.
|
|
77
|
+
* @returns Approximate RGB triple.
|
|
78
|
+
*/
|
|
65
79
|
function ansi256ToRgb(idx) {
|
|
66
80
|
if (idx >= 232) {
|
|
67
81
|
const gray = (idx - 232) * 10 + 8;
|
|
@@ -77,6 +91,16 @@ function ansi256ToRgb(idx) {
|
|
|
77
91
|
bi > 0 ? bi * 40 + 55 : 0,
|
|
78
92
|
];
|
|
79
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Compute squared Euclidean distance between two RGB colors.
|
|
96
|
+
* @param r1 - Red channel of the first color.
|
|
97
|
+
* @param g1 - Green channel of the first color.
|
|
98
|
+
* @param b1 - Blue channel of the first color.
|
|
99
|
+
* @param r2 - Red channel of the second color.
|
|
100
|
+
* @param g2 - Green channel of the second color.
|
|
101
|
+
* @param b2 - Blue channel of the second color.
|
|
102
|
+
* @returns Squared Euclidean distance (no sqrt for performance).
|
|
103
|
+
*/
|
|
80
104
|
function colorDistance(r1, g1, b1, r2, g2, b2) {
|
|
81
105
|
return (r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2;
|
|
82
106
|
}
|
|
@@ -84,8 +108,8 @@ function colorDistance(r1, g1, b1, r2, g2, b2) {
|
|
|
84
108
|
// RGB → ANSI 16
|
|
85
109
|
// ---------------------------------------------------------------------------
|
|
86
110
|
/**
|
|
87
|
-
* The 16 standard ANSI colors in RGB, indexed 0
|
|
88
|
-
* 0
|
|
111
|
+
* The 16 standard ANSI colors in RGB, indexed 0-15.
|
|
112
|
+
* 0-7: standard, 8-15: bright variants.
|
|
89
113
|
*/
|
|
90
114
|
const ANSI16_PALETTE = [
|
|
91
115
|
[0, 0, 0], // 0: black
|
|
@@ -106,10 +130,15 @@ const ANSI16_PALETTE = [
|
|
|
106
130
|
[255, 255, 255], // 15: bright white
|
|
107
131
|
];
|
|
108
132
|
/**
|
|
109
|
-
* Map an RGB color to the nearest ANSI 16 color index (0
|
|
133
|
+
* Map an RGB color to the nearest ANSI 16 color index (0-15).
|
|
110
134
|
*
|
|
111
135
|
* Uses Euclidean distance in RGB space to find the closest match
|
|
112
136
|
* among the 16 standard terminal colors.
|
|
137
|
+
*
|
|
138
|
+
* @param r - Red channel (0-255).
|
|
139
|
+
* @param g - Green channel (0-255).
|
|
140
|
+
* @param b - Blue channel (0-255).
|
|
141
|
+
* @returns ANSI 16 color index (0-15).
|
|
113
142
|
*/
|
|
114
143
|
export function rgbToAnsi16(r, g, b) {
|
|
115
144
|
let bestIdx = 0;
|
|
@@ -129,6 +158,8 @@ export function rgbToAnsi16(r, g, b) {
|
|
|
129
158
|
// ---------------------------------------------------------------------------
|
|
130
159
|
/**
|
|
131
160
|
* Convert an ANSI 256 color index to the nearest ANSI 16 color index.
|
|
161
|
+
* @param code - ANSI 256 color index (0-255).
|
|
162
|
+
* @returns ANSI 16 color index (0-15).
|
|
132
163
|
*/
|
|
133
164
|
export function ansi256ToAnsi16(code) {
|
|
134
165
|
const clamped = Math.max(0, Math.min(255, Math.round(code)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downsample.js","sourceRoot":"","sources":["../../../src/core/theme/downsample.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"downsample.js","sourceRoot":"","sources":["../../../src/core/theme/downsample.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,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IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7D,+BAA+B;IAC/B,IAAI,OAAO,GAAG,EAAE;QAAE,OAAO,OAAO,CAAC;IAEjC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -1,22 +1,48 @@
|
|
|
1
1
|
import type { Theme } from './tokens.js';
|
|
2
|
+
/** A single Design Token Community Group (DTCG) token with a typed value. */
|
|
2
3
|
export interface DTCGToken {
|
|
4
|
+
/** Token type descriptor (e.g. 'color', 'gradient', 'string'). */
|
|
3
5
|
$type?: string;
|
|
6
|
+
/** The token's value, which may be a string, object, array, or a `{reference}`. */
|
|
4
7
|
$value: unknown;
|
|
8
|
+
/** Optional human-readable description of the token. */
|
|
5
9
|
$description?: string;
|
|
6
10
|
}
|
|
11
|
+
/** A named group of DTCG tokens or nested groups. */
|
|
7
12
|
export interface DTCGGroup {
|
|
8
13
|
[key: string]: DTCGToken | DTCGGroup;
|
|
9
14
|
}
|
|
15
|
+
/** A top-level DTCG document containing token groups and/or individual tokens. */
|
|
10
16
|
export interface DTCGDocument {
|
|
11
17
|
[key: string]: DTCGToken | DTCGGroup;
|
|
12
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert a DTCG document into a bijou Theme.
|
|
21
|
+
* @param doc - DTCG document containing token groups for status, semantic, border, ui, and gradient.
|
|
22
|
+
* @returns Fully-populated Theme with all built-in keys resolved.
|
|
23
|
+
*/
|
|
13
24
|
export declare function fromDTCG(doc: DTCGDocument): Theme;
|
|
25
|
+
/**
|
|
26
|
+
* Convert a bijou Theme into a DTCG document for interop/export.
|
|
27
|
+
* @param theme - Theme to serialize.
|
|
28
|
+
* @returns DTCGDocument with all theme groups as DTCG token groups.
|
|
29
|
+
*/
|
|
14
30
|
export declare function toDTCG(theme: Theme): DTCGDocument;
|
|
15
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Load a single theme from a DTCG JSON file using the provided IO port.
|
|
33
|
+
* @param io - IO adapter with a `readFile` method.
|
|
34
|
+
* @param path - File path to the JSON theme file.
|
|
35
|
+
* @returns Parsed Theme.
|
|
36
|
+
*/
|
|
16
37
|
export declare function loadTheme(io: {
|
|
17
38
|
readFile(path: string): string;
|
|
18
39
|
}, path: string): Theme;
|
|
19
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Load all `.json` files from a directory and return them as a theme record keyed by theme name.
|
|
42
|
+
* @param io - IO adapter with `readDir`, `readFile`, and `joinPath` methods.
|
|
43
|
+
* @param dirPath - Directory path to scan for theme JSON files.
|
|
44
|
+
* @returns Record mapping theme names to parsed Themes (malformed files are silently skipped).
|
|
45
|
+
*/
|
|
20
46
|
export declare function loadThemesFromDir(io: {
|
|
21
47
|
readDir(path: string): string[];
|
|
22
48
|
readFile(path: string): string;
|